PHP 4.0 Bug #7492 Updated: array_rand function not random

From: Date: Sat, 28 Oct 2000 04:35:17 +0000
Subject: PHP 4.0 Bug #7492 Updated: array_rand function not random
Groups: php.dev 
Request: Send a blank email to php-dev+get-36187@lists.php.net to get a copy of this message
ID: 7492 Updated by: andrei Reported By: tim@spyderweb.com.au Status: Closed Bug Type: Arrays related Assigned To: Comments: Fixed in CVS - thanks. Previous Comments: --------------------------------------------------------------------------- [2000-10-27 09:29:52] tim@spyderweb.com.au <!-- 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. --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7492

« previous php.dev (#36187) next »