Bug #75170 [NEW]: mt_rand() bias on 64-bit machines

From: Date: Thu, 07 Sep 2017 17:55:05 +0000
Subject: Bug #75170 [NEW]: mt_rand() bias on 64-bit machines
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210998@lists.php.net to get a copy of this message
From: nikic Operating system: PHP version: 7.1.9 Package: Math related Bug Type: Bug Bug description:mt_rand() bias on 64-bit machines Description: ------------ A bias in the PHP 7.1 implementation of mt_rand() on 64-bit systems has been reported by Solar Designer on the mailing list. See https://externals.io/message/100229 for more information. Test script: --------------- <?php mt_srand(1234567890); $total = 100000; $max = 0x66666666; $halves[0] = $halves[1] = 0; for ($i = 0; $i < $total; $i++) { $halves[mt_rand(0, $max - 1) / ($max / 2)]++; } printf("%.1f%% vs. %.1f%%\n", 100. * $halves[0] / $total, 100. * $halves[1] / $total); ?> Expected result: ---------------- 50.0% vs. 50.0% Actual result: -------------- 60.0% vs. 40.0% -- Edit bug report at https://bugs.php.net/bug.php?id=75170&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75170&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75170&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75170&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75170&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75170&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75170&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75170&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75170&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75170&r=support Expected behavior: https://bugs.php.net/fix.php?id=75170&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75170&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75170&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75170&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75170&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75170&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75170&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75170&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75170&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75170&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75170&r=mysqlcfg

« previous php.bugs (#210998) next »