CSPRNG Functions
PHP Manual

random_int

(PHP 7)

random_intGenerates cryptographically secure pseudo-random integers

Description

int random_int ( int $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:

Parameters

min

The lowest value to be returned down to PHP_INT_MIN.

max

The highest value to be returned up to PHP_INT_MAX.

Return Values

Returns a crypto-secure random integer.

Errors/Exceptions

Issues an E_WARNING and returns FALSE when a sufficient source of randomness is unavailable.

Examples

Example #1 random_int() example

<?php
var_dump
(random_int(100999));
var_dump(random_int(-10000));
?>

The above example will output something similar to:

int(248)
int(-898)

See Also


CSPRNG Functions
PHP Manual