rand
Returns a random integer.
Syntax
rand(int $min = 0, int $max = getrandmax()): intParameters
| Parameter | Type | Description |
|---|---|---|
| $min | int | Optional. The lowest value. |
| $max | int | Optional. The highest value. |
Return value
intA random number within the bounds, inclusive.
Examples
A dice roll:
<?php
echo rand(1, 6);Notes
The numbers are predictable and unsuitable for passwords, tokens or prize draws. Use random_int() for those.
See also
- mt_rand — Returns a random integer.
- random_int — Returns a random integer from a range.
- array_rand — Returns a random key of an array.
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.