在samples for PCG中,他们只选择一种我认为是最佳/首选实践的方式:
pcg32 rng(pcg_extras::seed_seq_from<std::random_device>{});
或
// Seed with a real random value, if available
pcg_extras::seed_seq_from<std::random_device> seed_source;
// Make a random number engine
pcg32 rng(seed_source);
然而,在我的机器上运行它只会每次生成相同的种子。如果我只是键入一些整数来自己种子,那就不差了。如果以这种方式尝试,播种的好方法是什么并不起作用?
答案 0 :(得分:1)
pcg_extras::seed_seq_from
应该是推荐的方式,但它会将实际的种子生成委托给模板参数中指定的生成器。
MinGW的std::random_device
实施失败。所以此时,如果你想定位MinGW,你不能使用std::random_device
。
一些潜在的替代方案:
boost::random_device
seed11::seed_device
,替代std::random_device
(免责声明:它是我自己的图书馆)有关this blog post by M.E. O'Neill中播种的详细信息。