php8.5
Home/ Manual/ random / functions/ mt_srand

mt_srand

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Seeds the Mersenne Twister Random Number Generator

Description

mt_srand(int|null $seed = null, int $mode = MT_RAND_MT19937): void

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

Randomseed Mt19937-tiny-seed

Parameters

seed

Fills the state with values generated with a linear congruential generator that was seeded with seed interpreted as an unsigned 32 bit integer.

If seed is omitted or null, a random unsigned 32-bit integer will be used.

mode

Use one of the following constants to specify the implementation of the algorithm to use.

  • MT_RAND_MT19937: The correct Mt19937 implementation, available as of PHP 7.1.0.
  • MT_RAND_PHP Uses an incorrect Mersenne Twister implementation which was used as the default up till PHP 7.1.0. This mode is available for backward compatibility.

Feature-8-3-0

Return Values

Void

Changelog

VersionDescription
8.3.0seed is now nullable.
7.1.0srand()has been made an alias of mt_srand().
7.1.0mt_rand()has been updated to use the fixed, correct, version of the Mersenne Twister algorithm. To fall back to the old behaviour, use mt_srand() with MT_RAND_PHP as the second parameter.

See Also

Source: reference/random/functions/mt-srand.xml · from the official PHP manual (php/doc-en)