note 12857 modified in function.shuffle by irc-html

From: Date: Sat, 19 Jan 2002 22:11:49 +0000
Subject: note 12857 modified in function.shuffle by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25513@lists.php.net to get a copy of this message
Shuffle didn't work well at all, for me. I seeded it and it still wasn't random. I wrote my own function below, it seems to work better, for me: function array_rand_elim (&$array1, $array2 = array ()) { if (!count ($array1)) return array1; srand ((double) microtime() * 10000000); $rand = array_rand ($array1); $array2[] = $array1[$rand]; unset ($array1[$rand]); return $array2 + array_rand_elim ($array1, $array2); } $array = array_rand_elim ($array); --was-- Shuffle didn't work well at all, for me. I seeded it and it still wasn't random. I wrote my own function below, it seems to work better, for me: function array_rand_elim (&$array1, $array2 = array ()) { if (!count ($array1)) return array (); srand ((double) microtime() * 10000000); $rand = array_rand ($array1); $array2[] = $array1[$rand]; unset ($array1[$rand]); return $array2 + array_rand_elim ($array1, $array2); } $array = array_rand_elim ($array); http://www.php.net/manual/en/function.shuffle.php

« previous php.notes (#25513) next »