Page 1 of 1

less flawed random number generator

Posted: Mon Aug 30, 2004 5:53 am
by jasongr
Hello

I have read that the rand() function is quite flawed in the "random" numbers it is generating. I know that I can call srand like so:

Code: Select all

srand(make_seed());
before invoking rand(), and in fact as of PHP 4.2.0, there is no need to seed the random number generator as this is now done automatically.

Does anyone know of a better random number generator that I can use for PHP?

Jason

Posted: Mon Aug 30, 2004 6:27 am
by Lord Sauron
What about writing your own random generator ;-)

Posted: Mon Aug 30, 2004 8:20 am
by jasongr
rand() is not very random.
Basically number i has some correllation to number i-1.
If I use rand() to generate a very long list of numbers there is a fair probability that the distribution of the numbers won't be uniform.

True random genrators are implemented in hardware.
I am looking for an improvement for the rand() function if anyone knows of one

Posted: Mon Aug 30, 2004 10:04 am
by feyd
[php_man]mt_rand[/php_man]