PHP | gmp_random_range() Function Last Updated : 25 Apr, 2018 Comments Improve Suggest changes Like Article Like Report The gmp_random_range() is an inbuilt function in PHP which generates a random number.The random number thus generated lies between range min to max. Here GMP refers to (GNU Multiple Precision) which is for large numbers. Syntax: gmp_random_range ( GMP $min, GMP $max ) Parameters: The function accepts two parameters, GMP $min number representing lower bound for the random number and GMP $max number to represent the upper bound of the random number. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. Return Value: The function returns a random GMP number in the range $min-$max. Examples: Input : lower bound=0, upper bound =100 Output : 25 Input : lower bound=-100, upper bound=-10 Output : -23 Note:Output will vary every time on execution Below programs illustrate the use of gmp_random_range() function: Program 1: The program below demonstrates the working of gmp_random_range() function when numeric strings are passed as arguments. php <?php // PHP program to demonstrate the gmp_random_range() function // numeric string as arguments $min = "-200"; $max = "-100"; $rand = gmp_random_range($min, $max); echo $rand; ?> Output: -165 Program 2: The program below demonstrates the working of gmp_random_range() when GMP number is passed as an argument. php <?php // PHP program to demonstrate the gmp_random_range() function // GMP numbers as arguments $min = gmp_init("1000", 2); $max = gmp_init("1000000", 2); $rand = gmp_random_range($min, $max); // gmp_strval converts GMP number to string // representation in given base(default 10). echo gmp_strval($rand) . "\n"; ?> Output: 30 Reference: http://php.net/manual/en/function.gmp-random-range.php Comment More infoAdvertise with us Next Article PHP | gmp_random_range() Function T Twinkl Bajaj Follow Improve Article Tags : Misc Web Technologies PHP PHP-gmp Practice Tags : Misc Similar Reads PHP | gmp_random() Function The gmp_random() function is an inbuilt function in PHP which generates a random number. The range of random number will be in between zero and the number of bits per limb ( A limb is an internal GMP mechanism. The number of bits in a limb is not static and it can vary from system to system. Usually 2 min read PHP | gmp_random_seed() Function The gmp_random_seed() is an inbuilt function in PHP which sets the RNG seed( Random Number Generation). Syntax: void gmp_random_seed ( mixed $seed ) Parameters: The gmp_random_seed() function accepts a single parameter as mentioned above and explained below: $seed: It is the only parameter required 2 min read PHP | gmp_random_bits() Function The gmp_random_bits() function is an inbuilt function in PHP which generates a random number. The random number will thus be between the range 0 and (2 * bits) - 1. Here bits must be greater than 0, and the maximum value of bits is restricted by available memory. Here GMP refers (GNU Multiple Precis 2 min read PHP | gmp_rootrem() Function The gmp_rootrem() is a built-in function in PHP which is used to calculate the nth root of a GMP number (GNU Multiple Precision : For large numbers) and returns the integer component of the nth root and its remainder . Syntax : gmp_rootrem($num,$n) Parameters : This function accepts two mandatory pa 2 min read PHP mt_rand( ) Function While working with algorithms we often come across situations when we need to generate random integers. The most common way to generate random numbers is using Mersenne Twister. The Mersenne Twister is a pseudorandom number generator which got its name derived from the fact that its period length is 2 min read Like