【发布时间】:2014-02-28 21:10:13
【问题描述】:
我正在使用不支持<chrono> 的Visual Studio 2010,所以我必须播种default_random_engine。因此,我决定使用rand 播种,如下所示
srand((unsigned int)time(NULL));
std::default_random_engine engine(rand());
std::normal_distribution<double> randn(0.0, 0.3);
而不是下面的
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine engine(seed);
std::normal_distribution<double> randn(0.0, 0.3);
我得到了我期望通过这两种方法获得的东西。我的问题是使用 rand() 有什么需要注意的地方吗? (注:我别无选择使用<chrono>
【问题讨论】:
-
您可能想阅读pcg-random.org/posts/cpp-seeding-surprises.html 的博客,了解使用少数数字播种和/或使用当前时间播种时出现的问题。
-
@KaspervandenBerg,很棒的链接。非常感谢。
标签: visual-studio-2010 c++11 random