PHP mt_rand () function
Examples
Generates a random number:
<?php
echo(mt_rand() . "<br>");
echo(mt_rand() . "<br>");
echo(mt_rand(10,100));
?>
echo(mt_rand() . "<br>");
echo(mt_rand() . "<br>");
echo(mt_rand(10,100));
?>
Running instance »
Definition and Usage
mt_rand () function uses the Mersenne Twister algorithm to generate a random integer.
Tip: This function generates a random value is a better choice, return results as fast as RAND () 4 times function.
Tip: If you want a between 10 and 100 (including 10 and 100) of the random integer, use mt_rand (10,100).
grammar
mt_rand();
or
mt_rand( min,max );
or
mt_rand( min,max );
参数 | 描述 |
---|---|
min | 可选。规定返回的最小数。默认是 0。 |
max | 可选。规定返回的最大数。默认是 mt_getrandmax() 。 |
technical details
return value: | Between min (or 0) and max (or mt_getrandmax ()) (inclusive) between the random integer. If max <min returns FALSE. |
---|---|
Return type: | Integer |
PHP version: | 4+ |
PHP Update Log: | PHP 4.2.0: random number generator is automatically seeded. PHP 5.3.4: If max <min then report a E_WARNING and return FALSE. |
PHP Math Reference