引自cppreference :
std::random_device is a non-deterministic random number engine, although implementations are allowed to implement std::random_device using a pseudo-random number engine if there is no support for non-deterministic random number generation.
有没有办法检查当前的实现是否使用 PRNG 而不是 RNG(然后说错误退出),如果没有,为什么不呢?
请注意,一点谷歌搜索表明至少 MinGW 以这种方式实现了 std::random_device
,因此如果 std::random_device
是真正的危险被使用。
---编辑---
此外,如果答案是否定的,并且有人可以就为什么没有这样的功能/特征/某物提供一些见解,我会非常感兴趣。
最佳答案
Is there a way to check whether current implementation uses PRNG instead of RNG (and then say exit with an error) and if not, why not?
有一个方法:std::random_device::entropy
如果它是根据随机数引擎实现的(也就是说,它是确定性的),将返回 0.0
。
来自标准:
double entropy() const noexcept;
Returns: If the implementation employs a random number engine, returns
0.0
. Otherwise, returns an entropy estimate for the random numbers returned byoperator()
, in the rangemin()
tolog_2(max() + 1)
.
关于c++ - 有没有办法检查 std::random_device 是否实际上是随机的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27886761/