#19343 [Opn->Fbk]: array_rand does not return keys randomly
ID: 19343
Updated by: iliaa@php.net
Reported By: catch@sonaware.net
-Status: Open
+Status: Feedback
Bug Type: Arrays related
Operating System: WinXP
PHP Version: 4.2.3
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php4-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-latest.zip
I've just tested this function using latest CVS (unstable) in Windows
XP. The code from your example has worked properly. Therefor I am
closing the bug report.
Previous Comments:
------------------------------------------------------------------------
[2002-11-04 16:34:28] catch@sonaware.net
I see that another person has reproduced the bug. In my original
submission I specified my OS as Windows XP. iliaa@php.net may have not
tested the function on windows, therefore I think it warrants
reopening. My example is sufficient to quickly reproduce the bug.
------------------------------------------------------------------------
[2002-10-04 17:23:37] matthias.thalmann@sciontec.com
Well - I experienced the same problems (array_rand() is [still] not
random) in a Windows environment as catch@sonaware.net does. I actually
was looking forward to a new release as this 'bug' was reported to be
corrected and found the 4.2.3 release to act the same wrong way than
'before'.
This must be a problem on the Windows side, for in the Linux
environment I really get random values ...
------------------------------------------------------------------------
[2002-09-17 22:08:34] iliaa@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php
Thank you for your interest in PHP.
I've tried this a few dosen times and the results were quite random.
Please keep in mind that with a small array, such as the one in your
example, there are only 24 possible combinations. Which means, that on
average every 24th run you'll get an 'unsorted' array.
------------------------------------------------------------------------
[2002-09-10 14:09:42] catch@sonaware.net
I called array_rand($my_array, count($my_array)). I expected array_rand
to return the keys of $my_array in random order. I actually received
the keys in almost the same order each time. $my_array was a 4 element
array and the third element's key never changed position. I tried using
srand also, but it produced same results. On an older version of
php(4.1.2) the function worked as expected.
script on WinXP php4.2.3:
$numbers = range (1,4);
$rand_keys = array_rand ($numbers, count($numbers));
foreach ($rand_keys as $val) {
print $numbers[$val]."\n";
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19343&edit=1
Thread (6 messages)