ID: 50825
Updated by: [email protected]
Reported By: xeriar at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Debian Squeeze
PHP Version: 5.2.12
New Comment:
As both implemenations are not ideal, this specific is not fixable and
won't be.
Btw, if you use better random sources, getting a 50/50 as you expect is
very unlikely .)
Previous Comments:
------------------------------------------------------------------------
[2010-01-22 16:42:56] xeriar at gmail dot com
Description:
------------
Whenever rand () or mt_rand () are passed with a min=0, 0 gets reported
less often than it should be. mt_rand (0,1) returns 1 75% of the time,
for example, while mt_rand (1,2) works as expected.
Reproduce code:
---------------
<?php
$arr = array ();
for ($i = 0; $i < 100000; $i++)
{
$c = mt_rand (0,1);
if (!isset ($arr[$c])) $arr[$c] = 1;
else $arr[$c]++;
}
ksort ($arr);
foreach ($arr as $key => $value)
echo '<b>'.$key.':</b> '.$value.'<br />';
Expected result:
----------------
0 and 1 should each get ~50,000 results
Actual result:
--------------
0 gets ~25k results and 1 gets ~75k
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50825&edit=1