c++ - 为什么 mersenne_twister_engine 保证某些结果?

标签 c++ c++11 random

我在 cppreference's article for std::mersenne_twister_engine 上注意到以下内容(例如 std::mt19937):

The 10000th consecutive invocation of a default-constructed std::mt19937 is required to produce the value 4123659995.

The 10000th consecutive invocation of a default-constructed std::mt19937_64 is required to produce the value 9981545732273789042.

假设对标准的这种解释是准确的,那有什么关系呢?为什么存在这些保证?这不是非随机吗?

最佳答案

从提案中,N1398 :

How can a user have confidence that the implementation of a random-number engine is exactly as specified, correctly taking into account any platform pecularities [sic] (e.g., odd-sized ints)? After all, minor typos in the implementation might not be apparent; the numbers produced may look "random". This proposal therefore specifies for each engine the 10000th number in the random number sequence that a default-constructed engine object produces.

因此,它只是一个相对任意的“路径点”,被选择为确保实现符合此 PRNG 语义的一种方式。

它本身不是语义约束;这是实现是否符合要求的验证

IMO 可能需要在标准文本中添加注释,因为这是一种前所未有的双重检查实现质量的方法。 (我不知道有任何其他功能的实现 QoI 可以通过标准文本本身给出的样本数据来验证。)

功劳归于Blastfurnace对于first arriving at this notion .

关于c++ - 为什么 mersenne_twister_engine 保证某些结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54876332/

相关文章:

mysql - 从mysql中的大表中快速选择随机行

c++ - 使用 boost::optional 时避免临时

c++ - 如何在修改容器时正确迭代容器?

c++ - 什么时候计算右值?

c++ - 为什么这个模板特化在 GCC 中不起作用?

python - 我可以用 python 生成真实的随机数吗?

c - 如何生成大的随机数 C

c++ - 如何在复制构造函数中调用重载的下标?

c++ - 有没有办法抑制cppclean问题?

c++ - 模板成员类的模板别名