PHP | gmp_random() Function Last Updated : 11 Jul, 2025 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: https://www.php.net/manual/en/function.gmp-random.php Comment P priya_1998 Follow 0 Improve P priya_1998 Follow 0 Improve Article Tags : Web Technologies PHP PHP-function PHP-gmp Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like