# random number generator

• 06-04-2005
Verbenaca
random number generator
Hi. I was wondering if I can make the pseudo-random rand() function more random?
I'm generating a random number between 0 and 2 for 30 times:

for(int i=1; i<=30; i++)

Also, is there a better way than using the current time as the seed, so the sequences generated are more different from each other?

Thanks
• 06-04-2005
okinrus
Quote:

Hi. I was wondering if I can make the pseudo-random rand() function more random?
I'm generating a random number between 0 and 2 for 30 times:
You create your own 64 random bit generator by using several calls to rand.

Quote:

Also, is there a better way than using the current time as the seed, so the sequences generated are more different from each other?
If you could find something more random? Some hardware chips might have a special way to get a random number seed.
• 06-04-2005
Zach L.
Google for PRNGs (pseudo-random number generators). Some examples of different types are: linear congruential generator, and the mersenne twister (been a while since I've looked in much depth into this stuff, so its a little slow coming to my mind).

Also, you might want to check into the DIEHARD tests.

And, chapter 7 of Numerical Recipes, available here: http://library.lanl.gov/numerical/bookcpdf.html
• 06-06-2005
vasanth
i had seen some applications which use the mouse movement values as a seed... i guess those will give better random values..
• 06-06-2005
Darryl
Quote:

Originally Posted by Verbenaca

Also, is there a better way than using the current time as the seed, so the sequences generated are more different from each other?

Thanks

Use a higer resolution timer ... I've run into problems using time(), especially if using a script to run a simulation for example. If the program return really fast, when your script runs the next iteration the seed will often be the same because time() is the same. It's resolution is only 1 second so often 2 or 3 iterations may complete in under a second giving you the same seed.