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 replies to this topic
#1
Posted 30 October 2010 - 07:05 AM
|
|
|
#2
Posted 30 October 2010 - 09:21 AM
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
Posted 30 October 2010 - 09:24 AM
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.
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


Sign In
Create Account


Back to top









