note 10952 deleted from function.srand by nlopess

From: Date: Sun, 22 Feb 2004 10:38:03 +0000
Subject: note 10952 deleted from function.srand by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65533@lists.php.net to get a copy of this message
Note Submitter: MakeMoolah@themail.com ---- I'm no expert in PHP programming, but I do have an idea as to why you should not call srand more than once. The random number function is a formula based in the parser's code itself. Because all of this is parsed to quickly, the time will be pretty much the same every time that you call it. Since the formula looks at its previous responses and adds them in somewhere. If you don't understand, make a page like this: echo(srand(5) . "\n"); echo(srand(5) . "\n"); echo(srand(5) . "\n"); You should get the same response for each line... because you used the same seed over again. The difference in time betweed parsing your first call and your second is so small, it's like putting in a 5 over and over again. To get around this problem (in BASIC at least) you call it once and then every other time, just use srand() so that you get a better, more random, response.

« previous php.notes (#65533) next »