Re: cvs: php4 /ext/standard rand_mt.c rand_sys.c

From: Date: Tue, 04 Sep 2001 15:04:47 +0000
Subject: Re: cvs: php4 /ext/standard rand_mt.c rand_sys.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7205@lists.php.net to get a copy of this message
On Tue, 4 Sep 2001, Andrei Zmievski wrote: > On Mon, 03 Sep 2001, Jeroen van Wolffelaar wrote: > > array_rand was buggy anyway (the algorithm is wrong), so instead of wasting > > my time on a half-done patch, I rather fix the real problem, i.e. implement > > an other algorithm. And to freely quote Zeev: > > I haven't heard complaints that array_rand() was bogus. Explain, please. I can't speak to array_rand(), which I've never used. (But looking at the current code, it seems be okay.) However, shuffle() does /not/ produce a random shuffling of elements. It rearranges them, but not with an equal likelyhood of distribution. I know this for three reasons: 1) User contributed comments in the manual notes. 2) I wrote a little script to shuffle() an array N times and count the number each result appeared -- and it wasn't equal. 3) The mathematical logic is wrong because some elements get a higher chance to move than others. See Perl Cookbook for a short discussion about this and a better algorithm. -adam -- adam maccabee trachtenberg adam@trachtenberg.com

« previous php.cvs (#7205) next »