PHP 4.0 Bug #7492: array_rand function not random

From: Date: Fri, 27 Oct 2000 13:29:52 +0000
Subject: PHP 4.0 Bug #7492: array_rand function not random
Groups: php.dev 
Request: Send a blank email to php-dev+get-36129@lists.php.net to get a copy of this message
From: tim@spyderweb.com.au Operating system: Linux (RedHat 6.2) PHP version: 4.0.2 PHP Bug Type: Arrays related Bug description: array_rand function not random <!-- short reproducible error script srand ((double) microtime() * 10000000); $count = sizeof($files); $rand_keys = array_rand ($files, $count); reset ($files); while (list ($key, $val) = each ($rand_keys)) { echo "$key -> $val<br>\n"; } //--> The nature of the bug is in tryign to create a random distribution of the entire array. The function works perfectly provided the second parameter to the array_rand function is less than the total number of elements. If the second parameter is equal to the total number of elements i nthe array, then the result of array_rand is identical to the initial array. -- Edit Bug report at: http://bugs.php.net/?id=7492&edit=1

« previous php.dev (#36129) next »