Re: Predictable-random array
| From: | Jason Barnett | Date: | Mon, 20 Jun 2005 17:28:47 +0000 |
| Subject: | Re: Predictable-random array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-217235@lists.php.net to get a copy of this message | ||
Dotan Cohen wrote:
I've got an array $items which has about 200 entires. I want to print them out in random order, but as usual, I have a catch! I need to add a 'key' so that if need be, I can always return to the same 'random' order, like so: $items=predicatable_random($items, "qwerty");Try using multi-dimensional arrays, something like: <?php $items = array(1,2,3,4,5,6,7,8,9,10); for($i = 1, $random[0] = $items, shuffle($random[0]); $i < 10; $i++) { /* Initialize each pass with previous array, then randomize */ $random[$i] = $items; shuffle($random[$i]); } $selected = rand(0,10); echo "There are a total of " . count($random) . " randomly sorted arrays. Here are the randomly shuffled numbers for array number $selected.\n"; /* Now you can access each random array */ print_r($random[$selected]); ?> -- NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-general&w=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php