random_int

Get a cryptographically secure, uniformly selected integer

&reftitle.description; `int` `random_int` `int` `min` `int` `max`

Generates a uniformly selected integer between the given minimum and maximum.

The randomness generated by this function is suitable for all applications, including the generation of long-term secrets, such as encryption keys.

&csprng.sources; &csprng.function.backport;
&reftitle.parameters;

`min`

- The lowest value to be returned.

`max`

- The highest value to be returned.

&reftitle.returnvalues;

A cryptographically secure, uniformly selected integer from the closed interval [`min`, `max`]. Both `min` and `max` are possible return values.

&reftitle.errors;

&csprng.errors;

- If `max` is less than `min`, a `ValueError` will be thrown.

&reftitle.changelog;

&Version; | &Description;
8.2.0 | In case of a CSPRNG failure, this function will now throw a `Random\RandomException`. Previously a plain `Exception` was thrown.

&reftitle.examples;

### `random_int` example

    <?php
    var_dump(random_int(100, 999));
    var_dump(random_int(-1000, 0));
    ?>

&example.outputs.similar;

    int(248)
    int(-898)

&reftitle.seealso;

- `Random\Randomizer::getInt`
- `random_bytes`