Edit report at http://bugs.php.net/bug.php?id=54235&edit=1
ID: 54235 Updated by: [email protected] Reported by: guenhwyvar dot 68781 at gmail dot com Summary: array_rand doesn't like the 31st value of an array -Status: Open +Status: Bogus Type: Bug Package: Arrays related PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. No bug here. Previous Comments: ------------------------------------------------------------------------ [2011-03-11 23:47:12] guenhwyvar dot 68781 at gmail dot com Description: ------------ There is an odd behavior with array_rand: if the array has 32 or more values, then the 31st value is less likely to be "picked" than the others (the more values the array has, the less it is noticeable). This has been tested and confirmed on different versions of PHP, including 5.3.5 and 5.2.17. Test script: --------------- <?php $nbElements = 50; $test = array(); for ($i = 1; $i <= $nbElements; $i++) { $test[$i] = 0; } for ($i = 0; $i < 100000; $i++) { $test[array_rand($test)]++; } asort($test); echo '<pre>'; print_r($test); echo '</pre>'; ?> Expected result: ---------------- A (more or less) equal distribution between all the values (with the example given above, ~ 2,000 for each value). Actual result: -------------- Every time, the 31st value has been picked half what it "should" have been (meaning, to continue with the same example, around 1,000 times for the 31st value, where for all the others it's approximatively between 1,900 and 2,200): Array ( [31] => 1006 [10] => 1886 ⦠[44] => 2152 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54235&edit=1
