Generate random numbers:
<?phpecho(mt_rand() . "<br>");echo(mt_rand() . "<br>");echo(mt_rand(10,100));?>The mt_rand() function uses the Mersenne Twister algorithm to generate random integers.
Tip: This function is a better choice for generating random values, returning results 4 times faster than the rand() function.
Tip: If you want a random integer between 10 and 100, inclusive, use mt_rand (10,100).
mt_rand();ormt_rand( min,max );
parameter | describe |
---|---|
min | Optional. Specifies the minimum number to return. The default is 0. |
max | Optional. Specifies the maximum number to return. The default is mt_getrandmax(). |
Return value: | A random integer between min (or 0) and max (or mt_getrandmax()), inclusive. Returns FALSE if max < min . |
---|---|
Return type: | Integer |
PHP version: | 4+ |
PHP change log: | PHP 4.2.0: Random number generator automatically seeded. PHP 5.3.4: Report an E_WARNING and return FALSE if max < min . |