Below is a simple function to generate random numbers with PHP:
Usage: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;
}
?>
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.Code:$random_number = randomNumber(0,50);
Last edited by Paradine; 08-27-2007 at 05:09 PM.
Where is $total_sum declared?
Here:
// Return the number
return $total_sum;
}
?>
Whoops, hehe, my mistake. I've corrected the code now.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks