Bug #70003 [NEW]: mt_rand producing non random values

From: Date: Mon, 06 Jul 2015 18:47:43 +0000
Subject: Bug #70003 [NEW]: mt_rand producing non random values
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194158@lists.php.net to get a copy of this message
From: cjds at live dot com Operating system: Windows/ Linux 32 bits PHP version: 5.6Git-2015-07-06 (Git) Package: Math related Bug Type: Bug Bug description:mt_rand producing non random values Description: ------------ --- From manual page: http://www.php.net/function.mt-rand --- PHPs mt_rand function fails on 32 bit machines. It produces a certain value more than half the time. When the difference between the values are higher than the max_rand value then the system will return a certain value more than half the time. For example in the code given the system returns 1 more than 5000 times while generating 10000 random numbers Test script: --------------- $count=0; for ($i = 0; $i <= 10000; $i++) { $rand=mt_rand(-2147483608,2147483647); if($rand==1){$count++;} } echo('mt_getrandmax()='.mt_getrandmax().' count='.$count); Expected result: ---------------- mt_getrandmax()=2147483647 count=0 Actual result: -------------- mt_getrandmax()=2147483647 count=5034 -- Edit bug report at https://bugs.php.net/bug.php?id=70003&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70003&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70003&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70003&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70003&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70003&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70003&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70003&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70003&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70003&r=support Expected behavior: https://bugs.php.net/fix.php?id=70003&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70003&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70003&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70003&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70003&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70003&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70003&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70003&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70003&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70003&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70003&r=mysqlcfg

« previous php.bugs (#194158) next »