Jump to content

Generating random numbers

- - - - -

  • Please log in to reply
2 replies to this topic

#1
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
I want to generate some random numbers, how can i do this, im using nasm, is there a function and interrupt i can use or do i have to make my own random number generator, i think i can use the system clock isnt that how High Level languages generate random numbers?

#2
quikcarl

quikcarl

    Newbie

  • Members
  • Pip
  • 2 posts
You can use the system clock and other programs use different parts of the hardware to start the random number process. There is another way to generate random numbers and it's very sophisticated; it's called the Mersenne Twisterand can be found at: Mersenne Twister: A random number generator (since 1997/10)

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
They usually use a complicated mathematical algorithm that is highly sensitive to its starting value. I'll generate seemingly random numbers, but in reality if you seed the generator with the same value twice, you'll get the exact same numbers twice.

Using the system clock will get you numbers always in increasing order unless you force wraparound at some point. Is that what you want? If so, just use the rdtsc instruction to get the processor clock count in EDX:EAX. Note that this may cause an exception in protected mode if you're not running in ring 0; it depends on whether the TSD flag in CR4 is set or not. There's no way to read from CR4 in any ring but 0, so you can't check beforehand to avoid throwing an exception. I wouldn't use this, though. Maybe as a seed, but that's it.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users