note 67274 deleted from function.shuffle by danbrown

From: Date: Fri, 25 Jul 2008 17:48:39 +0000
Subject: note 67274 deleted from function.shuffle by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142722@lists.php.net to get a copy of this message
Note Submitter: bsl04 uark edu ---- I spoke too soon. Other readers spotted than Benton's code was a little wrong. What a mess this thread is. This stuff isn't PHP, but I believe it correctly implements Fisher-Yates. random(a, b) returns a number n such that a <= n <= b. The arrays start at 0. Hopefully this is enough to help someone who's trying to implement FY (in whatever language). i = data_length; if (i == 0) return; while (i--) { r = random(0, i); tmp = data[i]; data[i] = data[r]; data[r] = tmp; }

« previous php.notes (#142722) next »