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/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php