[PHP-DEV] PHP 4.0 Bug #7492 Updated: array_rand function not random From: andrei <email protected>
Date: 10/28/00

ID: 7492
Updated by: andrei
Reported By: tim <email protected>
Status: Closed
Bug Type: Arrays related
Assigned To:
Comments:

Fixed in CVS - thanks.

Previous Comments:
---------------------------------------------------------------------------

[2000-10-27 09:29:52] tim <email protected>
<!-- 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

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>