(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, such as when shuffling a deck of cards for a poker game.
As fontes de aleatoriedade dessa função são:
Nota: Embora essa função tenha sido adicionado no PHP 7.0, existe » implementação userland disponível para PHP 5.2 ao 5.6.
min
The lowest value to be returned, which must be
PHP_INT_MIN
or higher.
max
The highest value to be returned, which must be less than or equal to
PHP_INT_MAX
.
Returns a cryptographically secure random integer in the range
min
to max
, inclusive.
Exemplo #1 random_int() example
<?php
var_dump(random_int(100, 999));
var_dump(random_int(-1000, 0));
?>
O exemplo acima irá imprimir algo similar à:
int(248) int(-898)