How to Generate a Random Number in PHP
mt_rand()
the function used to generate the random number in PHP.
Syntax
1 2 |
<?php mt_rand(min,max); |
min: Optional. Specifies the lowest number to return. Default is 0.
max: Optional. Specifies the highest number to return. Max is 2147483647.
Example 1:
1 2 3 |
<?php $random_number=mt_rand(); echo $random_number; |
Example 2:
1 2 3 |
<?php $random_number=mt_rand(100000,9999999); echo $random_number; |