rand

PHP 4, PHP 5, PHP 7, PHP 8
rand - Generate a random integer

rand( ): int
intrand intmin intmax

Parameters

min

The lowest value to return (default: 0)

max

The highest value to return (default: getrandmax)

Return Values

A pseudo random value between min (or 0) and max (or getrandmax, inclusive).

Notes

Warning:

min max range must be within the range getrandmax. i.e. (max - min) <= getrandmax Otherwise, rand may return poor-quality random numbers.

Changelog

Version Description
7.2.0 rand has received a bug fix for a modulo bias bug. This means that sequences generated with a specific seed may differ from PHP 7.1 on 64-bit machines.
7.1.0 rand has been made an alias of mt_rand.

Related Functions

Example of rand

Show all examples for rand

PHP Version:


Function rand:

Mathematical Functions Functions

Most used PHP functions