Since: 8.2

final class Mt19937 implements Engine (View source)

Implements the Mt19937 (“Mersenne Twister”) algorithm.

Methods

__construct(int|null $seed = null, int $mode = MT_RAND_MT19937)

Constructs a new Mt19937 engine

string
generate()

Generate 32 bits of randomness

array
__serialize()

Serializes the Mt19937 object

void
__unserialize(array $data)

Deserializes the data parameter into a Mt19937 object

array
__debugInfo()

Returns the internal state of the engine

Details

__construct(int|null $seed = null, int $mode = MT_RAND_MT19937)

Constructs a new Mt19937 engine

Parameters

int|null $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.

int $mode

Use one of the following constants to specify the implementation of the algorithm to use. MT_RAND_MT19937: The correct Mt19937 implementation. MT_RAND_PHP: An incorrect implementation for backwards compatibility with mt_srand prior to PHP 7.1.0. This feature has been DEPRECATED as of PHP 8.3.0. Relying on this feature is highly discouraged.

string generate()

Generate 32 bits of randomness

Return Value

string

A non-empty string containing random bytes. The Random\Randomizer works with unsigned 64 bit integers internally. If the returned string contains more than 64 bit (8 byte) of randomness the exceeding bytes will be ignored. Other applications may be able to process more than 64 bit at once.

array __serialize()

Serializes the Mt19937 object

Return Value

array

void __unserialize(array $data)

Deserializes the data parameter into a Mt19937 object

Parameters

array $data

Return Value

void

No value is returned.

array __debugInfo()

Returns the internal state of the engine

Return Value

array