Home Tutorial Php Phpbasics Tutorial PHP Random Number

 
 

Share on Google+Share on Google+
PHP Random Number
Posted on: November 4, 2009 at 12:00 AM
Advertisement
PHP Random Number:In this tutorial you will learn about generation of random number in PHP. A random number is becoming more useful these days, like captcha, statistical sampling, cryptography

PHP Generate Random Numbers:

A random number is becoming more useful these days, like captcha, statistical sampling, cryptography, computer simulation etc. To generate random number, PHP provides rand() function. 

General Format int rand(void), int rand(int $min, int $max)
Parameters  $min: Minimum value $max: Maximum value
Return Value A random value

 Example :

<?php

echo "<b>rand() function will generate a random number as follows:</b>".rand();

echo "<br/><b>Same rand() function could generate another random number as follows:</b>".rand();

echo "<br/><b>rand() with parameter will generate a random number as follows:</b>". rand(2,10);

?>

First Output:

rand() function will generate a random number as follows:13638
Same rand() function could generate another random number as follows:13063
rand() with parameter will generate a random number as follows:2

Second Output (after refreshing the page):

rand() function will generate a random number as follows:14941
Same rand() function could generate another random number as follows:24530
rand()with parameter will generate a random number as follows:10

 

Advertisement

Related Tags for PHP Random Number:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 4, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com