gmp_random
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
gmp_random — Random number
WarningThis function has been
DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function
is highly discouraged.
Description
function gmp_random(
int $limiter = 20):
GMP
A limb is an internal GMP mechanism. The number of bits in a limb is
not static, and can vary from system to system. Generally, the number
of bits in a limb is either 32 or 64, but this is not guaranteed.
Caution
This function does not generate cryptographically secure values, and must not
be used for cryptographic purposes, or purposes that require returned values to be unguessable.
If cryptographically secure randomness is required, the Random\Randomizer may be
used with the Random\Engine\Secure engine. For simple use cases, the random_int()
and random_bytes() functions provide a convenient and secure API that is backed by
the operating system’s CSPRNG.
Parameters
limiter
-
The limiter.
A GMP object, an int,
or a string that can be interpreted as a number following the same logic
as if the string was used in gmp_init() with automatic
base detection (i.e. when base is equal to 0).
Return Values
A random GMP number.
Examples
Example #1 gmp_random() example
<?php
$rand1 = gmp_random(1); // random number from 0 to 1 * bits per limb
$rand2 = gmp_random(2); // random number from 0 to 2 * bits per limb
echo gmp_strval($rand1) . "\n";
echo gmp_strval($rand2) . "\n";
?>
The above example will output:
1915834968
8642564075890328087