What is gmp_random_range in PHP?

gmp_random_range is a function in PHP that generates a random number between two numbers passed as an argument.

Syntax


gmp_random_range(GMP|int|string $minimum, GMP|int|string $maximum): GMP

Parameters

The function takes in two parameters, minimum and maximum. minimum is the lower bound, whereas maximum is the upper bound for the random number.


minimum and maximum can be a numeric string, GMP object, or the int type.


Return value

The function returns a random number, i.e., between minimum and maximum.

Code

<?php
// random number between 0 and 1000
$random1 = gmp_random_range(0, 1000);
echo gmp_strval($random1) . "\n";
?>

Output


555

The output above may vary whenever the code is run. This is because every time, a random number is going to be generated.

Free Resources