PHP rand () function
Examples
Generates a random number:
<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>
Running instance »
Definition and Usage
rand () function generates a random integer.
Tip: If you want a between 10 and 100 (including 10 and 100) of the random integer, use rand (10,100).
Tip: mt_rand () function is a better choice for generating random values, returning a result the speed of rand () 4 times function.
grammar
rand();
or
rand( min,max );
or
rand( min,max );
参数 | 描述 |
---|---|
min | 可选。规定返回的最小数。默认是 0。 |
max | 可选。规定返回的最大数。默认是 getrandmax() 。 |
technical details
return value: | Between min (or 0) and max (or mt_getrandmax ()) (inclusive) between the random integer. |
---|---|
Return type: | Integer |
PHP version: | 4+ |
PHP Update Log: | PHP 4.2.0: random number generator is automatically seeded. |
PHP Math Reference