e Learning

How to Generate Random Number in PHP 7

In this  Tutorial you are going to learn How to get Random Number in PHP 7.

PHP 7 has introduced a new built in function called random_int() which will generate the random number between given two integers.

random_int ( int $min , int $max )

min – Minimum number to return as a random number.
max – Maximum Value to return as a random number. Max value should be greater than the min number in order to get the random value.

Example

$random_number=random_int(1,20);
echo $random_number;

In this Example PHP 7 will Generate random number between 1 and 20 including the 1 and 20.

$random_number=random_int(1,6);
echo $random_number;

Above Example will return a random number between 1 and 6 including the 1 and 6.