PHP mt_rand( ) Function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report 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 chosen to be a Mersenne prime. It was the first pseudorandom number generator to provide fast generation of high-quality pseudorandom integers. It was designed specifically to rectify most of the flaws found in older pseudorandom number generators. So in PHP, there is an inbuilt function mt_rand() which is based on Mersenne Twister which helps in generating random numbers. The mt_rand() function generates a random integer between the specified minimum and maximum values. It produces a better random value and is faster than the rand() function. You may also refer to the article on PHP | rand() Function which is another inbuilt function in PHP to generate random numbers. Syntax: int mt_rand($min, $max) Parameters: This function accepts two parameter which are described below: $min : It is an optional parameter. It specifies the lowest number to be returned.The default value is 0. $max : It is an optional parameter. It specifies the highest number to be returned. Return Value: It returns a random number between min (or 0) and max and the return type is integer. Examples: Input : mt_rand() Output : 34567 Input : mt_rand(15, 50) Output : 49 Below programs illustrate the working of mt_rand() in PHP: Program 1: PHP <?php echo mt_rand(); ?> Output: 34567 Program 2: PHP <?php echo mt_rand(15, 50); ?> Output: 49 Important points to note : mt_rand() function generates a random integer using the Mersenne Twister algorithm. It produces a better random value and is faster than the rand() function. Reference: http://php.net/manual/en/function.mt-rand.php Comment More infoAdvertise with us Next Article PHP mt_rand( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads 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 | 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_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 array_rand() Function This inbuilt function of PHP is used to fetch a random number of elements from an array. The element is a key and can return one or more than one key. On a practical basis, this is not that useful because the function uses pseudo-random number generator that is not suitable for cryptographic purpose 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_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 p5.js random() Function The random() function in p5.js is used to return a random floating point number between ranges given as the parameter. Syntax: random(Min, Max) or random(Array) Parameters: This function accepts three parameters as mentioned above and described below: Min: This is the lower bound of the random numbe 3 min read PHP uniqid( ) Function The uniqid() function in PHP generates a unique identifier based on the current time in microseconds. It creates a string that is highly unlikely to duplicate during execution, making it useful for generating unique tokens, filenames, or session IDs. Optional parameters enhance uniqueness.Syntax uni 3 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 Like