我有一堆关于随机引擎和分布、它们的成本和交互的问题:
- Is
std::random_device
an expensive (heavy constructible) object? Should I only create one for my application if possible? - Are
RandomNumberDistribution
objects expensive objects or is it mostly dependent of concrete distribution? It seems to me that for exampleuniform_int_distribution
should be very light object containing distribution range[min, max]
and may be (?) some internal state. How does the interaction between
random_device
,random_engine
anddistribution
work in code below:std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> distr(1, 10); auto random_value = distr(gen);
[0, 10]
?显然,某些对象的内部状态在调用后应该被修改:肯定是random_device
、random_engine
,但是uniform_int_distribution
是否也有一些内部状态呢?
<random>
的轻松阅读材料。 这是一个绝佳的参考,具有出色的示例。 - WhozCraig