Ok, thanks for the tip :)

Justin


on 13/03/03 7:53 PM, Ernest E Vogelsinger ([EMAIL PROTECTED]) wrote:

> 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.
> 
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to