#19343 [NEW]: array_rand does not return keys randomly

From: Date: Tue, 10 Sep 2002 19:09:42 +0000
Subject: #19343 [NEW]: array_rand does not return keys randomly
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18973@lists.php.net to get a copy of this message
From:             catch@sonaware.net
Operating system: WinXP
PHP version:      4.2.3
PHP Bug Type:     *General Issues
Bug description:  array_rand does not return keys randomly

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 bug report at http://bugs.php.net/?id=19343&edit=1
-- 
Try a CVS snapshot:  http://bugs.php.net/fix.php?id=19343&r=trysnapshot
Fixed in CVS:        http://bugs.php.net/fix.php?id=19343&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=19343&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=19343&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=19343&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=19343&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=19343&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=19343&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=19343&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=19343&r=globals



Thread (6 messages)

« previous php.bugs (#18973) next »