Random\Engine\Mt19937::__construct

(PHP 8 >= 8.2.0)

Random\Engine\Mt19937::__constructConstructs a new Mt19937 engine

说明

public Random\Engine\Mt19937::__construct(?int $seed = null, int $mode = MT_RAND_MT19937)

警告

由于 Mt19937(“梅森旋转算法”)引擎仅接受 32 位整数作为种子,因此尽管 Mt19937 的范围为 219937-1,但可能的随机序列数量仅限于 232(即 4,294,967,296)。

当依赖隐式或显式随机播种时,重复会出现得更早。根据生日问题,在少于 80,000 个随机生成的种子后,预计重复种子的概率为 50%。在随机生成大约 30,000 个种子后,重复种子的概率为 10%。

This makes Mt19937 unsuitable for applications where duplicated sequences must not happen with more than a negligible probability. 如果需要可重复的种子,Random\Engine\Xoshiro256StarStarRandom\Engine\PcgOneseq128XslRr64 引擎都支持更大的种子,它们不太可能随机碰撞。如果不需要再现性,Random\Engine\Secure 引擎提供加密安全随机性。

警告

本函数还未编写文档,仅有参数列表。

参数

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.
  • MT_RAND_PHP: An incorrect implementation for backwards compatibility with mt_srand() prior to PHP 7.1.0.

范例

示例 #1 Random\Engine\Mt19937::__construct() example

<?php
// Uses a random 32 Bit seed.
$e = new \Random\Engine\Mt19937();

$r = new \Random\Randomizer($e);
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top