ID:               45301
 Comment by:       payton2558 at googlemail dot com
 Reported By:      payton2558 at googlemail dot com
 Status:           Open
 Bug Type:         Unknown/Other Function
 Operating System: Windows XP 32, Vista 32
 PHP Version:      5.2.6
 New Comment:

Here's the shortest version. Try varying the array_fill num parameter.
Lower numbers appear to increase the randomness.

Appears problem is array_rand interfering with the random seed but
please investigate further than that as I'm certain I experienced this
problem before ever using array_rand (rand(0,count($a)-1) works in its
place and doesn't trigger bug in this example). 

<?php
        
$a = array_fill(0, 100000, "word");

for ($i=0; $i<20; $i++) {
        
        array_rand($a);
        
        echo rand(1,9999)."\n";
}
?>


Previous Comments:
------------------------------------------------------------------------

[2008-06-18 18:06:09] sv4php at fmethod dot com

Confirmed on Apache 2.2, Windows XP SP2 with PHP 5.2.6.

Confirmed also without building files (just building the array directly
in a loop).

Requires Windows, doesn't seem to affect mt_rand();

------------------------------------------------------------------------

[2008-06-18 16:20:47] [EMAIL PROTECTED]

On a related note: #45184

------------------------------------------------------------------------

[2008-06-18 16:05:00] payton2558 at googlemail dot com

Description:
------------
The reproduce code demonstrates the bug. You can modify the code in
different ways to affect the severity of the output.

Appears to require Windows.
Please note I have tested on 2 different machines and 3 versions of
php. I have also confirmed this with a couple of users on IRC.

mt_rand may also be affected but not as badly

Unrelated: bugs.php your CAPTCHA system is the worst I could ever
expect for a programming related group

Reproduce code:
---------------
<?php
function RandomNumber() {
        
        $word1 = file('word1.txt');      // word1 and word2.txt can be made by
fwriting "word\n" 50000 times. Different filesizes affect bug.
        $word2 = file('word2.txt');
                
        $rword1 = trim($word1[array_rand($word1)]);
        $rword2 = trim($word2[array_rand($word2)]);
        
        $rnum = rand(1,999);    
        
        return $rnum;
}

for ($i=0; $i<20; $i++) {
        
        echo RandomNumber()."\n";
}
?>

Expected result:
----------------
20 random looking numbers

Actual result:
--------------
20 identical numbers or in other cases, severely unrandom numbers


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45301&edit=1

Reply via email to