You are here: Re: Predictable-random array « PHP « IT news, forums, messages
Re: Predictable-random array

Posted by Jason Barnett on 06/20/05 20:28

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация