How to generate random number in PHP?

Date February 18, 2006

Sometimes we need to have a random quote, news, testimonials being displayed on the front page of a website. We can use random number function to get a random id of a data to be generated.

The code is as below

——

$maxnum = 10;
srand(time());
$random_num = (rand()%$maxnum);
echo “The random number is: ” . $random_num;

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>