# Pseudo Random Sequence

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

•  Subject
• Author
• Posted on
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:
T,G,Q,C,I,N,E,A

On the 2nd day you ALWAYS get
G,I,A,N,E,T,Q,N

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,

Nel.

## Re: Pseudo Random Sequence

"Nel" wrote:

(snip)

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

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

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

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

## Re: Pseudo Random Sequence

Philip Ronan wrote:

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

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

--
E. Dronkert

## Re: Pseudo Random Sequence

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!!!

Nel.

## Re: Pseudo Random Sequence

Following on from Nel's message. . .

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
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex  <http://www.eminent.demon.co.uk