Edit report at https://bugs.php.net/bug.php?id=61963&edit=1

 ID:                 61963
 User updated by:    bsnxff at gmail dot com
 Reported by:        bsnxff at gmail dot com
-Summary:            array_rand seed no refresh bug
+Summary:            array_rand seed use up
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 Operating System:   window xp sp3
 PHP Version:        5.3.12
 Block user comment: N
 Private report:     N

 New Comment:

No one going to take this bug?


Previous Comments:
------------------------------------------------------------------------
[2012-05-06 11:42:59] bsnxff at gmail dot com

Description:
------------
run test_array_rand.php


Test script:
---------------
<?php
$array = array_fill(0, 1000, 'a');
echo rand(0 , 10000);
function ref(&$data = false)
{
    global $array;
    $data = &$array;
    $a = randArray($data);
}
function randArray($data)
{
    global $array;
    //may be wrong here
    $array[] = array_rand($array, 1);
    return $data[rand(0, sizeof($data) - 1)];
}
$i = 1000;
while ($i--)
    ref()
    
// Hi refresh it 3 - 10 times
// you will see
// random number no longer random

// 1 return 10
// 2 return 4453
// 3 return 1251
// 4 return 10
// 5 return 4453
// 6 return 1251
// ...
?>

Expected result:
----------------
make rand(0, 10000) random

Actual result:
--------------
rand(0, 10000) no longer random


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



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

Reply via email to