Pseudo Random Sequence

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I am driving myself crazy trying to think of a solution to this - perhaps  
one of you guys can see a simple solution.

The problem is displaying the contents of an array in what appears to be  
random order, but in fact is a set sequence depending on a given value (e.g.  
the day of the month).

So on the 1st of the month the array is always displayed as:

On the 2nd day you ALWAYS get

The order itself is not important, but what is important is the apparent  
random sequence is really repeatable.

Hope you can make some sense out of this.

Many thanks,


Re: Pseudo Random Sequence

"Nel" wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

Seed the random number generator based on the day of the month and use
array_rand() to shuffle the contents

$day = 1 * date('j');
$random_array = array_rand($array);

(I haven't tested this, but it ought to work)

phil [dot] ronan @ virgin [dot] net

Re: Pseudo Random Sequence

Philip Ronan wrote:
Quoted text here. Click to load it

Yep, only it's shuffle()...
Gives the same results every time:

  $a = range('A', 'Z');
  for ( $i = 1; $i < 32; ++$i )
    $b = $a;
    echo sprintf('%2d ', $i).implode(' ', $b)."\n";

E. Dronkert

Re: Pseudo Random Sequence

Quoted text here. Click to load it

Thanks to you both for your advice - unless you've come across such a  
feature before it's hard to know if such a thing is possible so easily.

Thanks again!!!


Re: Pseudo Random Sequence

Following on from Nel's message. . .
Quoted text here. Click to load it
The simple solution is to look at the documentation.  What do you see  
there.... srand()

PETER FOX Not the same since the bra business went bust
2 Tees Close, Witham, Essex.
Gravity beer in Essex  <

Site Timeline