Re: Predictable-random array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/20/05, Marek Kilimajer <lists@xxxxxxxxxxxxx> wrote:
> 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");
> >
> > so for each place that I need the items rearranged, I will replace
> > qwerty with a different string, and get a different 'random' order. I
> > haven't played around with it much as I stumbled into a brick wall
> > fairly early and can't get much going. Any ideas?
> >
> > I tried to play with usort, uksort, ksort, and various combinations
> > with shuffle. The 'randomization' can be based on qualities of each
> > string, such as 'sort alphebetically by the 7th character', so I
> > thought that I'd try that, but I got lost in explodes and such.
> 
> Seed the generator with some integer using srand():
> 
> srand(384884);
> $a = range(0, 100);
> shuffle($a);
> print_r($a);
> 

Thanks! That's exactly the simple solution I was looking for. With the
current versions of php not needing a seed, I didn't even think to do
that!

I also recieved many other suggestions, and I will look into them. All
in the name of learning. Thank you.

Dotan
http://english-lyrics.com/el/index.php
English Song Lyrics

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux