Below is a simple function to generate random numbers with PHP:
PHP Code:
<?php
##########################################
# Input: Minimum number,
# Maximum number
##################################
function randomNumber($min, $max)
{
// setup our seed
srand((float) microtime() * 10000000);
// Generate the number
$random = rand($min,$max);
// Return the number
return $random;
}
?>
Usage:
PHP Code:
$random_number = randomNumber(0,50);
Note: As of PHP 4.2.0, there is no need to seed the random number generator with
srand() or
mt_srand() as this is now done automatically.