(PHP 7)
random_int — Generates cryptographically secure pseudo-random integers
$min
, int $max
)Generates cryptographic random integers that are suitable for use where unbiased results are critical (e.g. shuffling a Poker deck).
The sources of random are as follows:
min
The lowest value to be returned down to PHP_INT_MIN
.
max
The highest value to be returned up to PHP_INT_MAX
.
Returns a crypto-secure random integer.
Issues an E_WARNING
and returns FALSE
when a sufficient source of randomness is unavailable.
Example #1 random_int() example
<?php
var_dump(random_int(100, 999));
var_dump(random_int(-1000, 0));
?>
The above example will output something similar to:
int(248) int(-898)