php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7492 array_rand function not random
Submitted: 2000-10-27 09:29 UTC Modified: 2000-10-28 00:35 UTC
From: tim at spyderweb dot com dot au Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.2 OS: Linux (RedHat 6.2)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tim at spyderweb dot com dot au
New email:
PHP Version: OS:

 

 [2000-10-27 09:29 UTC] tim at spyderweb dot com dot 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-28 00:35 UTC] andrei@php.net
Fixed in CVS - thanks.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Aug 20 22:01:30 2019 UTC