1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Monday, July 13, 2009

Random Number generation in PHP

function randomdigit($digits) {
static $startseed = 0;
if (!$startseed) {
$startseed = (double)microtime()*getrandmax();
srand($startseed);
}
$range = 8;
$start = 1;
$i = 1;
while ($i<$digits) {
$range = $range . 9;
$start = $start . 0;
$i++;
}
return (rand()%$range+$start);
}
?>

1 comment:

  1. I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


    Susan

    http://dclottery.info

    ReplyDelete

Related Posts with Thumbnails