12 December 2009

PHP Random Number Generator

This is a very simple php random number generator script.

Creating a random number takes two commands; srand and rand. srand is a preparation command for rand. It helps rand create a truely random number, rand itself creates the random number.
The $from variable is the lowest number possible, and $to is the highest number possible. Simple edit the two variables to suit your requirements.

$from = 0;
$to = 100;
srand ((double) microtime( )*1000000);
$random_number = rand($from, $to);
echo "$random_number";


Post a Comment