PHP | gmp_random_bits() Function Last Updated : 08 Jun, 2018 Comments Improve Suggest changes Like Article Like Report 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 Precision) which is for large numbers. Syntax : GMP gmp_random_bits ( int $bits ) Parameters : The above function accepts a single parameter as mentioned above and described below : $bits : IT accepts only one parameter This parameter can be a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 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. Examples: Input : bits = 3 Output : 3 Input : bits = 5 Output : 15 Note: Output will vary every time on execution Program 1 : php <?php // PHP program to demonstrate // the gmp_random_bits() function // random number within 0 to 15 $rand = gmp_random_bits(4); echo gmp_strval($rand) . "\n"; ?> Output: 10 Program 2 : php <?php // PHP program to demonstrate // the gmp_random_bits() function // random number within 0 to 31 $rand = gmp_random_bits(5); // gmp_strval converts GMP number to string // representation in given base(default 10). echo gmp_strval($rand) . "\n"; ?> Output: 15 Reference:http://php.net/manual/en/function.gmp-random-bits.php Comment More infoAdvertise with us Next Article PHP | gmp_random_bits() Function P priya_1998 Follow Improve Article Tags : Misc Web Technologies PHP PHP-function 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 | random_bytes () Function The random_bytes()is an inbuilt function in PHP. The main function is to generate cryptographically secure pseudo-random bytes. It generates cryptographic random bytes of arbitrary string length. The different sources of randomness used in this function, they are as follows:- Window : CryptGenRandom 1 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 | gmp_div_r() Function The gmp_div_r() function is an in-built function in PHP which performs the division operation between two GMP numbers (GNU Multiple Precision : For large numbers) and returns the remainder. Syntax : gmp_div_r($num1, $num2) Parameters : This function accepts two GMP numbers, $num1 and $num2 as mandat 2 min read Like