srand()

srand() — Seed the random number generator.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Seeds the random number generator with seed or with a random value if no seed is given.

Signature

srand(?int $seed = null, int $mode = MT_RAND_MT19937): void

Parameters

ParameterTypeWhat it takes
$seed?intFills the state with values generated with a linear congruential generator that was seeded with seed interpreted as an unsigned 32 bit integer.

Return value

No value is returned.

Example

The PHP manual ships no example for srand(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.3.0seed is now nullable.
7.1.0srand() has been made an alias of mt_srand().

See also

rand(), getrandmax(), mt_srand()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page srand() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.