Re: seeding srand()...

From: Date: Sun, 08 Oct 2000 20:09:08 +0000
Subject: Re: seeding srand()...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19110@lists.php.net to get a copy of this message
Doh! Never mind, I was just forgetting to reset the arrays. My bad... At 11:57 AM 10/8/00 -0700, you wrote:
I have a quick and dirty little script for a multiple choice test. The user make all the choices on one page, submits it, and is taken to the next page to view the answers. To try and spice things up a bit, after I read in all the questions and answers from a flat file i randomize the order. for example: $seed = (double)microtime()*1000000; srand($seed); shuffle($answer_array); I then pass the value of $seed to the next script in a hidden form variable. The exact routine runs again, only this time I seed srand() with the old value. I figured that this would "randomize" everything in the same order it did on the first page, but alas it does not. Perhaps I misunderstand what srand() actually does or how to seed it. If someone has any hints I'd appreciate it! - Craig Simons


« previous php.general (#19110) next »