#43171 [Opn]: nonrandom rand() results in lower bits
| From: | bdew at druzya dot org | Date: | Thu, 01 Nov 2007 13:54:25 +0000 |
| Subject: | #43171 [Opn]: nonrandom rand() results in lower bits | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-119206@lists.php.net to get a copy of this message | ||
ID: 43171
User updated by: bdew at druzya dot org
Reported By: bdew at druzya dot org
Status: Open
Bug Type: Math related
Operating System: windows xp sp2
PHP Version: 5.2.4
New Comment:
Err, sory...
"If i use rand(x,y) the bug does happen only when
max_rand+2>y>max_rand+2"
should have read
"If i use rand(x,y) the bug does happen only when
max_rand+2>y>max_rand-2"
Previous Comments:
------------------------------------------------------------------------
[2007-11-01 13:30:23] bdew at druzya dot org
Description:
------------
Under windows xp cli version, rand() seems to return cycling values in
lower bits.
If i use rand(x,y) the bug does happen only when
max_rand+2>y>max_rand+2
mt_rand() is unaffected
Tested same code under linux cli and the bug doesn't happen.
possibly related to http://bugs.php.net/bug.php?id=43108
Reproduce code:
---------------
$a=rand() & 0xff;
for ($k=0;$k<10;$k++) {
$i=0;
do {
$i++;
$b=rand() & 0xff;
} while ($a!=$b);
echo("cycle: $i\n");
};
Expected result:
----------------
10 lines with "cycle: x", x being different every line
Actual result:
--------------
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
cycle: 256
every time
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43171&edit=1