php.net |  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
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-10 05:45 UTC] waldschrott@php.net
There?s no information in the docs which logic shuffle() uses, should be added....
 [2002-10-01 15:36 UTC] hholzgra@php.net
there's a more recent report ob php 4 behaviour
 [2002-10-01 16:22 UTC] sniper@php.net
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: Sat Mar 28 23:01:23 2020 UTC