← All built-ins / rand()

rand()

rand(...$args): int

Parameters

NameTypeDescription
$minintlower bound (inclusive)optional
$maxintupper bound (inclusive)optional

Return value

Pseudo-random integer, in the range when given (not crypto-secure).

Example

$d = rand(1, 6);
echo $d >= 1 && $d <= 6 ? "dice-ok" : "bad";
dice-ok

See also

mt_rand()srand()random_int()shuffle()