note 46713 deleted from function.shuffle by bobby
| From: | bobby@php.net | Date: | Mon, 06 Aug 2007 14:37:33 +0000 |
| Subject: | note 46713 deleted from function.shuffle by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129217@lists.php.net to get a copy of this message | ||
Note Submitter: al at giicorp dot com
----
When shuffling large sets this got a faster response, since $array is always the same size, those
extra millisecs counts.
function fisherYatesShuffle(&$array)
{
$total = count($array);// <--
for ($i = 0; $i<$total; $i++)
{
$j = @mt_rand(0, $i);
$temp = $array[$i];
$array[$i] = $array[$j];
$array[$j] = $temp;
}
}