note 40267 added to function.shuffle

From: Date: Thu, 26 Feb 2004 21:37:14 +0000
Subject: note 40267 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-65849@lists.php.net to get a copy of this message
Benton, Thanks for the corrections. The for loop is corrected in your code, but I believe you overlooked changing my error in the call to mt_rand() ($i, not $i+1). Below is your version with that trivial change: function fisherYatesShuffle(&$array) { for ($i = 0; $i<count($array); $i++) { $j = @mt_rand(0, $i); $temp = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $temp; } } ---- Manual Page -- http://www.php.net/manual/en/function.shuffle.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40267 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40267&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40267&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65849) next »