note 73934 added to function.mt-srand
| From: | slonmron_no_spam_please_ at yahoo dot com | Date: | Fri, 16 Mar 2007 07:44:04 +0000 |
| Subject: | note 73934 added to function.mt-srand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124501@lists.php.net to get a copy of this message | ||
Looks like mt_rand() gives same result for different seeds when the lowest bits are different only.
Try this:
#!/usr/bin/php -q
<?php
$min = -17;
$max = $min + 48; // 48 is to fit the results in my console
for ($testseed=$min; $testseed<$max; $testseed++)
{
mt_srand( $testseed );
$r = mt_rand();
printf("mt_srand( 0x%08x ): mt_rand() == 0x%08x == %d\n", $testseed, $r, $r);
}
?>
This is a snapshop of the results:
...
mt_srand( 0xfffffffc ): mt_rand() == 0x0a223d97 == 170016151
mt_srand( 0xfffffffd ): mt_rand() == 0x0a223d97 == 170016151
mt_srand( 0xfffffffe ): mt_rand() == 0x350a9509 == 889885961
mt_srand( 0xffffffff ): mt_rand() == 0x350a9509 == 889885961
mt_srand( 0x00000000 ): mt_rand() == 0x71228443 == 1898087491
mt_srand( 0x00000001 ): mt_rand() == 0x71228443 == 1898087491
mt_srand( 0x00000002 ): mt_rand() == 0x4e0a2cdd == 1309289693
mt_srand( 0x00000003 ): mt_rand() == 0x4e0a2cdd == 1309289693
...
I found this occationally. I have no idea if it is a bug or not. In my real life I do not intend to
use sequentional seeds. However, probably this may be important for somebody.
----
Server IP: 217.75.128.29
Probable Submitter: 82.103.91.3
----
Manual Page -- http://www.php.net/manual/en/function.mt-srand.php
Edit -- https://master.php.net/note/edit/73934
Del: integrated -- https://master.php.net/note/delete/73934/integrated
Del: useless -- https://master.php.net/note/delete/73934/useless
Del: bad code -- https://master.php.net/note/delete/73934/bad+code
Del: spam -- https://master.php.net/note/delete/73934/spam
Del: non-english -- https://master.php.net/note/delete/73934/non-english
Del: in docs -- https://master.php.net/note/delete/73934/in+docs
Del: other reasons-- https://master.php.net/note/delete/73934
Reject -- https://master.php.net/note/reject/73934
Search -- https://master.php.net/manage/user-notes.php