Just a simple question really. I got some help with a random number generation function, and the function works well enough, but I would really like to know why it has been made the way it is.
Code: Select all
function _rand_num($min = null, $max = null)
{
static $seeded;
if (!$seeded) {
mt_srand((double)microtime()*1000000);
$seeded = true;
}
if (isset($min) && isset($max)) {
if ($min >= $max) {
return $min;
} else {
return mt_rand($min, $max);
}
} else {
return mt_rand();
}
}Code: Select all
static $seeded;
if (!$seeded) {Isnt it just redundant. Wont $seeded, although static, always be valueless and thus always make seeding necessary.
If not, why. And what is the purpose if it has one.
Thanks.