Hi!
I am using shuffle() to shuffle an array; however, I want to make sure that or pretty sure that each time the program restarts, it will not be using the same shuffle. Should I randomized the shuffle using rand()? If so, do you know how I can actually do it?
Thanks,
Michael
Should I randomized the shuffle using rand()?
Why? Shuffle already does what it promises. It's simple enough to test, e.g. with this:
$arr = array(1, 2, 3, 4, 5); shuffle($arr); print_r($arr);
As per www.php.net/shuffle :
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
Installer wrote:Why? Shuffle already does what it promises. It's simple enough to test, e.g. with this:$arr = array(1, 2, 3, 4, 5); shuffle($arr); print_r($arr);
Thank you for your answer.
I guess what I was trying to say was does shuffle() always produce the same sequence of shuffled arrays every time it is restarted?
That's why I posted the code--so you could test it and see for yourself.
Got it! So shuffle() results in a "new" sequence everytime it is called. Thanks. I appreciate your getting back to me so soon.