|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-01-22 16:47 UTC] pajoye@php.net
[2010-01-22 17:23 UTC] xeriar at gmail dot com
[2010-01-22 17:59 UTC] pajoye@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 20 09:00:01 2025 UTC |
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