- microtime: documentation ( source)
- mt_rand: documentation ( source)
- mt_srand: documentation ( source)
- explode: documentation ( source)
<?php
echo roll_dice();
function roll_dice() {
mt_srand(make_seed());
return clamp(mt_rand(0,7),1,6);
}
function make_seed()
{
list($usec,$sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 65536); //100000
}
function clamp($in, $min, $max) {
return (int)(($in < $min) ? $min : ($in > $max) ? $max : $in);
}
?>