#45302 [NEW]: rand() after array_rand() produces the same numbers

From: Date: Wed, 18 Jun 2008 17:08:08 +0000
Subject: #45302 [NEW]: rand() after array_rand() produces the same numbers
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125852@lists.php.net to get a copy of this message
From: sv4php at fmethod dot com Operating system: Windows XP PHP version: 5.2.6 PHP Bug Type: *Math Functions Bug description: rand() after array_rand() produces the same numbers Description: ------------ This was discovered by another guy who asked me to verify it on my configuration (and I confirmed it). I'm not sure he reported it, so just in case I do as well. The example source code produced 989, 377, 989, 377 from rand() ad infinitum under Windows XP, Apache 2.2, PHP 5.2.6. Important: - Linux apparently not affected. - mt_rand() apparently not affected. Reproduce code: --------------- function RandomNumber() { $f1 = array(); for ($i = 0; $i < 50000; $i++) { $f1[] = true; } $k = array_rand($f1); $rnum = rand(1,999); return $rnum; } for ($i = 0; $i < 20; $i++) { echo RandomNumber()."\n"; // produces a sequence of 377, 989, 377, 989, 377, 989, 377... here } Expected result: ---------------- Random numbers. Actual result: -------------- Same number or narrow repeated sequence. -- Edit bug report at http://bugs.php.net/?id=45302&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45302&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45302&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45302&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45302&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45302&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45302&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45302&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45302&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45302&r=support Expected behavior: http://bugs.php.net/fix.php?id=45302&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45302&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45302&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45302&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45302&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45302&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45302&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45302&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45302&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45302&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45302&r=mysqlcfg

« previous php.bugs (#125852) next »