PHP rand()Functions

PHP Math 参考手册PHP Math Reference Manual

Examples

Generate random numbers:

<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(10,100));
?>

Run Example »

Definition and Usage

The rand() function generates a random integer.

Tip:If you want a random integer between 10 and 100 (inclusive of 10 and 100), use rand(10,100).

Tip:mt_rand()The mt_rand() function is a better choice for generating random values, and it returns results 4 times faster than the rand() function.

Syntax

rand();

or

rand(min,max);

Parameter Description
min Optional. Specifies the lowest number to return. Default is 0.
max Optional. Specifies the highest number to return. Default isgetrandmax()。

Technical Details

Return value: A random integer betweenmin(or 0) andmax(or mt_getrandmax()), inclusive.
Return type: Integer
PHP Version: 4+
PHP Changelog: PHP 4.2.0: The random number generator is seeded automatically.


PHP Math 参考手册PHP Math Reference Manual Other Extensions