PHP gmp_random() function

PHP has a built-in feature called gmp_random() that makes a random number. The range of numeric values will be between zero and the number of bits per limb, multiplied by the limiter.

A limb is the internal functionality or mechanism of the GMP function. The number of bits in a limb does not stay the same for each system. It is may different for another system of the GMP function. A limb usually has a default value of 16 or 32 bits, but this is not always the situation.

The random number is created on the function's limiter. If the limiter shows a negative value, the number generates negative output.

Syntax

The given syntax shows the GMP function to generate random data.

Parameters

  • The syntax shows essential single input parameters for the "gmp_random " function.
  • The parameter must be positive or negative numerical, integer, and string value converted into a number.
  • The string input parameter gets converted into numerical data.
  • The $limiter_value parameter sets the limiter to create a random value.

Return Value

As explained above, this function gives a random number as an output. The output data shows between 0(zero), and the number depends on the limb.

Examples

The given examples show the Random number of the GMP parameter. We can use integer, numerical, binary, and string GMP data.

Example1: the given example sets the "random number" of the positive input limiter

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Example2: The given example sets the "random number" of the negative input limiter.

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Example3: the given example sets the "random number" of the input value. Here, we use a variable with the integer data as an input.

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Example4: The given example sets the "random number" of the input value. Here, we use GMP parameter data as input. Here, we use the same input value but get different outputs.

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Example5: The given example sets the "random number" of the input value. Here, we use GMP parameter data as input. The input data uses a limiter with an index value and shows the difference between values.

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Example6: the given example sets the "random number" of the negative input value. The input data uses a negative limiter with an index value and shows the difference between outputs.

Output:

The given output sets the random values of the input values.

PHP gmp_random() function

Conclusion

The gmp_random() function shows random values of the given number. It works on positive, negative, integer, and string values and displays output value in minimum code.






Latest Courses