RE: [PHP] seeding using mt_srand();

From: Date: Wed, 16 Oct 2002 12:51:58 +0000
Subject: RE: [PHP] seeding using mt_srand();
Groups: php.general 
Request: Send a blank email to php-general+get-120184@lists.php.net to get a copy of this message
Hi Phil, > > > How often do you need to call mt_srand(); ? > > > > once per script, before generating any random > > numbers > > I can't just have the user load a file called > generate.php which has the mt_srand....and then > keep calling random.php (which has mt_rand) without > calling generate.php right? Well, you can if it's in one script :-) Let's say "random.php" looks like this: <?php echo mt_rand(); ?> and "main.php" looks like this: <?php include ("generate.php"); // seed include ("random.php"); include ("random.php"); include ("random.php"); ?> You should be fine. AIUI the call to mt_srand() lasts for the lifecycle of the script. Was that what you meant? Cheers Jon

« previous php.general (#120184) next »