php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17138 array_rand() is not random
Submitted: 2002-05-10 07:29 UTC Modified: 2002-06-03 14:00 UTC
Votes:8
Avg. Score:4.9 ± 0.3
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:2 (25.0%)
From: d dot crawford at blueyonder dot co dot uk Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.0 OS: Windows 98
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: d dot crawford at blueyonder dot co dot uk
New email:
PHP Version: OS:

 

 [2002-05-10 07:29 UTC] d dot crawford at blueyonder dot co dot uk
The code from the manual:

srand ((float) microtime() * 10000000);
$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand ($input, 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";

always returns the same array elements.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-21 17:56 UTC] matthias dot thalmann at sciontec dot com
I've experienced the same problem on Win2K and WinNT4, regardless what your seed for srand() is. In PHP 4.1.2 everything's fine.
 [2002-06-03 14:00 UTC] edink@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

The fix will be included in the next release of PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 03:01:32 2024 UTC