Why don't shuffle work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Why don't shuffle work?

Post by nick2 »

help,

Code: Select all

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

shuffle($color);

print $color
?>
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Which operating system are you using? shuffle() had me pulling my hair out when using it on Windows.

Mac
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Shows why it's always useful to state exactly what the problem is instead of just posting code...

Mac
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

Actually as of PHP 4.2.0 there is no need to seed the random number generator. http://php.net/srand
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
Post Reply