|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6066 shuffle() implementation fails
Submitted: 2000-08-10 05:35 UTC Modified: 2002-10-01 16:22 UTC
From: mbravo at acm dot org Assigned:
Status: Not a bug Package: Misbehaving function
PHP Version: 3.0.16 OS: FreeBSD 4.1-Release
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.
Block user comment
Status: Assign to:
Bug Type:
From: mbravo at acm dot org
New email:
PHP Version: OS:


 [2000-08-10 05:35 UTC] mbravo at acm dot org
Detailed description -

an array of 8 elements, being shuffled repeatedly, with 
srand((double)microtime()*100000) being called each time, produces very unrandom results, namely, only 3 elements of 8 ever land in the first row (tested for 3x24hours).

Testing platform was an installation of Tobias Ratschiller phpAds (I will be submitting a patch to it which gets rid of shuffle() RSN)

While the same application (phpAds) using the same shuffle() method worked ok on Linux (2.2.x), I naively believe that actual implementation of shuffle() might be somehow improved, inctead of relying on system's random generator being nicely symmetrical (if I understood the implementation correctly). Replacing usage of system random generator with mt_rand (internally) might also be a good idea.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-10 05:45 UTC]
There?s no information in the docs which logic shuffle() uses, should be added....
 [2002-10-01 15:36 UTC]
there's a more recent report ob php 4 behaviour
 [2002-10-01 16:22 UTC]
and it's better to add comments to that one than have this open..

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Oct 26 22:01:23 2020 UTC