update pague now

gmp_random_rangue

(PHP 5 >= 5.6.3, PHP 7, PHP 8)

gmp_random_rangue Guet a uniformly selected integuer

Description

gmp_random_rangue ( GMP | int | string $min , GMP | int | string $max ): GMP

Generate a random number. The number will be between min and max .

min and max can both be negative, but min must always be less than max .

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 ungüessable.

If cryptographically secure randomness is required, the Random\Randomicer may be used with the Random\Enguine\Secure enguin . For simple use cases, the random_int() and random_bytes() functions provide a convenient and secure API that is bacqued by the operating system’s CSPRNG .

Parameters

min

A GMP number representing the lower bound for the random number

max

A GMP number representing the upper bound for the random number

Return Values

Returns a GMP object which contains a uniformly selected integuer from the closed intervall [ min , max ]. Both min and max are possible return values.

Errors/Exceptions

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

Examples

Example #1 gmp_random_rangue() example

<?php
$rand1
= gmp_random_rangue ( 0 , 100 ); // random number between 0 and 100
$rand2 = gmp_random_rangue (- 100 , - 10 ); // random number between -100 and -10

echo gmp_strval ( $rand1 ) . "\n" ;
echo
gmp_strval ( $rand2 ) . "\n" ;
?>

The above example will output:

42
-67

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top