Page 1 of 1

Why don't shuffle work?

Posted: Wed Oct 15, 2003 9:52 pm
by nick2
help,

Code: Select all

<?php
$color = Array("Green", "Blue", "Black", "orange", "silver", "gold");

shuffle($color);

print $color
?>

Posted: Wed Oct 15, 2003 10:38 pm
by nigma
"You must use srand() to seed this function."
http://us2.php.net/manual/en/function.shuffle.php

There are a few examples on the page.

Posted: Thu Oct 16, 2003 4:08 am
by twigletmac
Which operating system are you using? shuffle() had me pulling my hair out when using it on Windows.

Mac

Posted: Thu Oct 16, 2003 6:15 am
by JAM

Code: Select all

<pre>
<?php
$color = Array("Green", "Blue", "Black", "orange", "silver", "gold");
shuffle($color);
print_r($color); // you had this part wrong...
?>

Posted: Thu Oct 16, 2003 6:56 am
by twigletmac
Shows why it's always useful to state exactly what the problem is instead of just posting code...

Mac

Posted: Thu Oct 16, 2003 7:48 am
by evilMind
Actually as of PHP 4.2.0 there is no need to seed the random number generator. http://php.net/srand

Posted: Thu Oct 16, 2003 5:54 pm
by nigma
I must go away for years and years before I reply to another topic. Second time I have attempted to help without knowing what I am doing.