我在 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 value4123659995
.The 10000th consecutive invocation of a default-constructed
std::mt19937_64
is required to produce the value9981545732273789042
.
假设对标准的这种解释是准确的,那有什么关系呢?为什么存在这些保证?这不是非随机吗?
最佳答案
从提案中,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 可以通过标准文本本身给出的样本数据来验证。)
关于c++ - 为什么 mersenne_twister_engine 保证某些结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54876332/