Dynamic Random Number Generation Using PHP

by Hiroshi on June 19, 2008

in Rand, Randomizing, Rotating Content

This one is my favorite script. It looks little but it can be used in many php applications or scripts to control or initiate things, if you know what I mean. We can generate a random number in between two specified digits.

Following example will generate a random number in between 673 and 62389.

*** For storing a function into a variable dont use “”.

<?php
$mynumber= rand(673,62389);
echo $mynumber;
?>

OR

<?php
print rand() . "<br />";
//generates and prints a random number
print rand(10, 30);
//generates and prints a random number between 10 and 30 (10 and 30 ARE included)
print rand(1, 1000000);
//generates and prints a random number between on and one million
?>
<?php
print rand();
?>
<?php
print rand(1, 1000000);
?>

Related Posts

Previous post:

Next post: