PHP gmp_random_range() function

The PHP gmp_random_range() function creates a random number between the given two input GMP numbers. This function works between the minimum and maximum numbers. It works on a positive and negative input value.

Syntax

The syntax shows the GMP function to get a random range between two numbers.

Parameters

  • As shown in the above GMP syntax, this function uses two GMP parameters or numerical data as a required parameter. The parameters are written as a $min_parameter and $max_parameter.
  • PHP version 5.6 and afterword versions use the gmp_random_range() function to get a range between two numbers.
  • The $min_parameter works as a minimum number or data of the function.
  • The $max_parameter represents the maximum data of the function.

Return Value

The function shows an output in number format to give a random range of the two values.

Examples

The given examples show the random value of the various GMP parameters.

Example1: the given example shows "random values" of the two input positive values.

Output:

The following output identifies the random values of the given values.

PHP gmp_random_range() function

Example2: the following example shows "random values" of the given negative and positive two input values. Here, we cannot use negative for the maximum number's parameter. The maximum parameter position is greater than the minimum parameter's position.

Output:

The following output identifies the random values of the given values.

PHP gmp_random_range() Function
Display random values of the given input data
The random value of a given numbers: 58
The random value of the given numbers: -27
The random value of the given numbers:
The random value of the given numbers: -25

Example3: the given example shows "random values" of the variable values.

Output:

The following output identifies the random values of the given values.

PHP gmp_random_range() function

Example4: the given example shows "random values" with the GMP parameters or values.

Output:

The following output identifies the random values of the given values.

PHP gmp_random_range() function

Example5: the given example shows "random values" with the binary GMP parameters or values.

Output:

The following output identifies the random values of the given values.

PHP gmp_random_range() function

Conclusion

The random value between two numbers or range is found using the gmp_random_range function. It is easy to operate on two values in mathematical operations using this function.






Latest Courses