|
|
 |
mt_srand (PHP 3>= 3.0.6, PHP 4 , PHP 5) mt_srand -- 播下一个更好的随机数发生器种子
php_public at macfreek dot nl
07-Oct-2001 11:57
The seed is not good. The make_seed() function returns a big number (around
1.0E14), this number is bigger then 2147483647, the max. size of an
integer. If the result of make_seed is first converted to an integer, which
-on my setup- always becomes -2147483648. So, the above code always returns
the same seed and I always end up with the same random
numbers.
Note: This might be related to a bug noted on http://www.php.net/manual/en/language.types.integer.php.
But I couldn't confirm this, since it will be fixed in PHP 4.0.7, but that
isn't released yet at the time of writing)
I was also not able to
fix it by return the seed modulo 2147483647.
So for now, I just suggest
change the seed function as:
function make_seed() {
return
(double)microtime()*1000000;
}
See also: uniqid()
| |