Bug #61963 [Nab]: array_rand seed use up
| From: | bsnxff at gmail dot com | Date: | Fri, 11 May 2012 11:46:09 +0000 |
| Subject: | Bug #61963 [Nab]: array_rand seed use up | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-170375@lists.php.net to get a copy of this message | ||
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 use up
Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: window xp sp3
PHP Version: 5.3.12
Block user comment: N
Private report: N
New Comment:
Thanks !
Previous Comments:
------------------------------------------------------------------------
[2012-05-11 07:30:31] rasmus@php.net
Yes, I tested your case. On my Linux box I get random values. Like I said, it
depends on your operating system's pseudo-random generator.
------------------------------------------------------------------------
[2012-05-11 07:27:30] bsnxff at gmail dot com
Have you tested this case?
rand() will return fixed values not random values.
but mt_rand() works
this is not what user expected.
<?php
$array = array_fill(0, 1000, 'a');
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();
//echo mt_rand(0 , 10000);
//echo "\n";
echo $array[rand(0, sizeof($array) - 1)];
?>
------------------------------------------------------------------------
[2012-05-11 07:17:21] bsnxff at gmail dot com
Yes mt_rand works :S
Me bad luck.
------------------------------------------------------------------------
[2012-05-11 04:42:19] rasmus@php.net
because it makes no sense and on operating systems with a decent random number
generator built in there is no bug. Windows XP is not such an operating system.
You can try mt_rand() and see if you have more luck with that. rand() gives you
the OS-native pseudo-random generator.
------------------------------------------------------------------------
[2012-05-11 04:04:42] bsnxff at gmail dot com
No one going to take this bug?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61963
--
Edit this bug report at https://bugs.php.net/bug.php?id=61963&edit=1