C ++ 11标准保证相同种子在实现中的相同随机数吗? [英] Does the C++11 standard guarantee identical random numbers for the same seed across implementations?

查看:338
本文介绍了C ++ 11标准保证相同种子在实现中的相同随机数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我在GCC和MSVC下使用完全相同的种子和参数实例化一个 std :: mt19937 ,我应该得到相同的随机数序列吗?如果这样,我认为这个属性将持有mersenne_twister_engine一般,因为mt19937只是一个具体的参数。这在C中的 rand()中不是这样的。它看起来像是在特定代码方面应用的标准文档,所以我怀疑它应该总是相同的,但是devil在细节...

For example if I instantiate a std::mt19937 with the exact same seed and parameters under GCC and under MSVC, should I get the same sequence of random numbers? If so I assume this property would hold for mersenne_twister_engine in general since mt19937 is just one with specific parameters. This is not true for rand() in C. It looks like the standard documents the transformations applied in terms of specific code, so I suspect it should always be the same, but the devil is in the details...

推荐答案

对于新的随机数引擎,是的,对于相同的种子和参数,将在所有平台上获得相同的值序列。对于 rand(),没有。您也没有对随机数分布的保证,即使他们输入相同的输入值序列。

For the new random number engines, yes, for the same seed and parameters you'll get the same sequence of values on all platforms. For rand(), no. You also don't have that guarantee with random number distributions, even when they are fed the same sequence of input values.

这篇关于C ++ 11标准保证相同种子在实现中的相同随机数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆