c++ - 有没有办法检查 std::random_device 是否实际上是随机的?

标签 c++ c++11 random

引自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 by operator(), in the range min() to log_2(max() + 1).

关于c++ - 有没有办法检查 std::random_device 是否实际上是随机的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27886761/

相关文章:

c++ - "if"c++ 中的语句不从左到右计算条件

c++ - 判断编译时是否支持thread_local关键字

matlab - 在 Matlab 中生成多元正态分布的随机数

r - 如何从二项式分布中生成随机数 1 和 2 而不是 0 和 1?

c++ - Gnuplot - 保存输出

c++ - 给定起始地址和大小访问内存中的图像

c++ - 相同类型重新定义的 Clang typedef(和别名)导致意外错误

algorithm - 关于随机数序列生成

c++ - 不能将 cout 与 MPI 一起使用

c++ - 在 C++ 中只读 1 个字符