Return to Snippet

Revision: 8229
at September 9, 2008 18:07 by digdan


Initial Code
function fyshuffle(&$items,$seedstring) {
   if (!$seedstring) {
      $seedval = time();
   } else {
      if (is_numeric($seedstring)) {
          $seedval = $seedstring;
      } else {
      for($i=0;$i<=strlen($seedstring);$i++) {
          $seedval += ord($seedstring[$i]);
      }
   }

   srand($seedval);
   for ($i = count($items) - 1; $i > 0; $i--) {
      $j = @rand(0, $i);
      $tmp = $items[$i];
      $items[$i] = $items[$j];
      $items[$j] = $tmp;
   }
}

Initial URL


Initial Description
Repeatable Fisher Yates Array Shuffle based on given random string. If no seed is provided the current second will be used (not to use as a pure random shuffle... based on microseconds)

Initial Title
Random Seeded Array Shuffle

Initial Tags
array

Initial Language
PHP