PHP Random Number


 

PHP Random Number

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 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

 

Ads