PHP | gmp_random() Function Last Updated : 19 Jun, 2018 Comments Improve Suggest changes Like Article Like Report 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, the number of bits in a limb is either 16 or 32 but this is not always true. ) multiplied by limiter .The number generated depends on the limiter i.e. if the limiter is negative then the number generated will also be negative. Syntax: GMP gmp_random ( int $limiter ) Parameters: The gmp_random() function accepts a single parameter as shown above and explained below: $limiter : It is the only required parameter accepted by the gmp_random() function. This parameter sets the limiter value. This parameter can be a GMP resource in PHP 5.5 or earlier, a GMP object in PHP version 5.6 and later, or also allowed to pass a numeric string provided that it is possible to convert that string to a number. Return Value: This function returns a random number between zero and the number of bits per limb as explained above. Below programs illustrate the gmp_random() function in PHP. Program 1: php <?php // php code implementing gmp_random() function // random number from 0 to 1 * bits per limb $rand = gmp_random(1); echo gmp_strval($rand) . "\n"; ?> Output: 1915834968 Program 2: php <?php // php code implementing gmp_random() function // random number from 0 to 2 * bits per limb $rand = gmp_random(2); echo gmp_strval($rand) . "\n"; ?> Output: 8642564075890328087 Related Articles: PHP gmp PHP | gmp_random_range() Function PHP | gmp_random_bits() Function Reference: http://php.net/manual/en/function.gmp-random.php Comment More infoAdvertise with us Next Article PHP | gmp_random() Function P priya_1998 Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-gmp Similar Reads 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_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_range() Function 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 accept 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 PHP | random_int() Function The random_int () is an inbuilt function in PHP. The main function is to generate cryptographically secure pseudo-random integers value. When unbiased results occur in critical condition, then generated cryptographic random integers are used.The different sources of randomness used in this function 2 min read PHP | gmp_powm() Function The gmp_powm() is an inbuilt function in PHP which is used to calculate the number raised to a power of two GMP numbers modulo of another GMP number.(GNU Multiple Precision: For large numbers)Syntax: gmp_pow( $base, $exp, $mod) Parameters: The function accepts three mandatory parameters $base, $exp 2 min read PHP | gmp_root() Function The gmp_root() is an in-built function in PHP which returns the integer part of the N-th root of a GMP number(GNU Multiple Precision: For large numbers).Syntax:  gmp_root( $num, $n ) Parameters: The function accepts two mandatory parameters $num and $n.  $num - This is the GMP number whose integer 2 min read PHP rand() Function In this article, we will see how to get the random number using the rand() function in PHP, along with knowing its implementation through the example. The rand() is an inbuilt function in PHP used to generate a random number ie., it can generate a random integer value in the range [min, max]. Syntax 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 | gmp_scan1() Function The gmp_scan1() is an inbuilt function which is used to scan "1" in the GMP number(GNU Multiple Precision : For large numbers) starting from given index which move towards most significant bits in the number. Syntax: gmp_scan1($num, $index) Parameters: This function accepts two parameters as explain 2 min read Like