播种default_random_engine? [英] seeding default_random_engine?
问题描述
我使用的Visual Studio 2010不支持< chrono>
,所以我必须种子 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>
我建议从 std :: random_device
获取种子, :
std :: default_random_engine engine(std :: random_device {}());
这将为您提供比
std :: time
。I'm using visual studio 2010 which doesn't support
<chrono>
, so I have to seeddefault_random_engine
. Thus, I've decided to seed it withrand
as followingsrand((unsigned int)time(NULL)); std::default_random_engine engine(rand()); std::normal_distribution<double> randn(0.0, 0.3);
instead of the following
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);
I'm getting what I'm expecting to acquire for both methods. My question is are there any considerations should I pay attention to by using rand()? (Note: I have no choice to use
<chrono>
解决方案I recommend grabbing a seed from
std::random_device
:std::default_random_engine engine(std::random_device{}());
which should provide you with significantly more entropy than
std::time
.这篇关于播种default_random_engine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!