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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 - 12 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 11:01:30 2024 UTC