Re: Force refresh of graphic - how?

From: Date: Thu, 13 Mar 2003 08:53:11 +0000
Subject: Re: Force refresh of graphic - how?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139458@lists.php.net to get a copy of this message
At 23:33 12.03.2003, Justin French said: --------------------[snip]-------------------- >Put this code in your shared library of functions (adapted from manual, >untested): ><? >function randNumber($min=1000,$max=99999) > { > // build a seed > list($usec, $sec) = explode(' ', microtime()); > $seed = (float) $sec + ((float) $usec * 100000); > > // seed random generator > srand($seed); > > // return random number > return rand($min,$max); > } >?> --------------------[snip]-------------------- May I? It's usually not a good idea to re-seed the randum number generator during a single script instance, as this might use the same seed more than once, resulting in the identical random sequence... To avoid reseeding, you could e.g. use a static variable in your randNumber() function: function randNumber($min=1000,$max=99999) { static $is_seeded = false; if (!$is_seeded) { $is_seeded = true; // build a seed list($usec, $sec) = explode(' ', microtime()); $seed = (float) $sec + ((float) $usec * 100000); // seed random generator srand($seed); } ... I prefer to add a string generated by uniqid(), such as <img src="myimg.jpg?r=<?php echo uniqid('',true);?>"> uniqid() uses the entropy generated by the opsys random device (if available) in an attempt to make this truly random. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#139458) next »