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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.