|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-02 11:47 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 07:00:01 2025 UTC |
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.