note 15892 added to function.mt-srand

From: Date: Sun, 07 Oct 2001 12:57:03 +0000
Subject: note 15892 added to function.mt-srand
Groups: php.notes 
Request: Send a blank email to php-notes+get-18658@lists.php.net to get a copy of this message
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() -- http://www.php.net/manual/en/function.mt-srand.php http://master.php.net/manage/user-notes.php?action=edit+15892 http://master.php.net/manage/user-notes.php?action=delete+15892 http://master.php.net/manage/user-notes.php?action=reject+15892

« previous php.notes (#18658) next »