English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The mt_rand() function in PHP

The mt_rand() function is used to generate random numbers. It generates numbers using the Mersenne Twister algorithm.

Note-This function is faster thanrand()Method is faster

Syntax

mt_rand()
or
mt_rand(min, max)

Parameter

  • min-Default is 0. The minimum number to return.

  • max-The maximum number to return.

Return

The mt_rand() function returns a random integer between min (or 0) and max. If max < min, it returns FALSE.

Example

<?php
   echo mt_rand(100, 200);
?>

Output result

144

Example

Let's look at another example-

<?php
   echo mt_rand();
?>

Output result

132850920