c++ - 如何找到 std::random_device 的 "true"熵?

标签 c++ c++11 random

我想检查我的 std::random_device 实现是否 具有非零熵(即非确定性),使用 std::random_device::entropy() 函数。然而,根据 至cppreference.com

"This function is not fully implemented in some standard libraries. For example, gcc and clang always return zero even though the device is non-deterministic. In comparison, Visual C++ always returns 32, and boost.random returns 10."

有没有办法找到真正的熵?特别是做现代 计算机(MacBook Pro/iMac 等)具有不确定的来源或随机性,例如使用散热监视器?

最佳答案

我向你推荐这篇文章的讲座。

Myths about /dev/urandom

§ 26.5.6

A random_device uniform random number generator produces non-deterministic random numbers.

If implementation limitations prevent generating non-deterministic random numbers, the implementation may employ a random number engine.

所以基本上它会尝试使用内部系统“真”随机数生成器,在 linux/dev/{u}random o windows RltGenRandom。

不同的一点是您不信任这些随机性来源,因为它们依赖于内部噪声或者是紧密的实现。

此外,您如何测量熵的质量,正如您所知,这是试图找到好的 rng 生成器的最大问题之一。

一种估计可能非常好,而另一种估计可能报告的熵不太好。

Entropy Estimation

In various science/engineering applications, such as independent component analysis, image analysis, genetic analysis, speech recognition, manifold learning, and time delay estimation it is useful to estimate the differential entropy of a system or process, given some observations.

正如它所说,你必须依赖最终的观察,而这些可能是错误的。

我你觉得内部rng不够好,你可以随时尝试为此购买硬件设备。这个list on wikipedia有供应商列表,您可以查看有关他们的互联网评论。

性能

您必须考虑的一点是使用实随机数生成器在应用程序中的性能。一种常见的技术是在 mersenne twister 中使用通过/dev/random 获得的数字作为种子。

如果用户无法物理访问您的系统,您需要在可靠性和可用性之间取得平衡,一个有安全漏洞的系统就像一个不能工作的系统一样糟糕,最后您必须对您的重要数据进行加密。

编辑 1:作为建议,我已将文章移至评论顶部,是一本不错的读物。感谢您的提示:-)。

关于c++ - 如何找到 std::random_device 的 "true"熵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28390843/

相关文章:

c - c中(0,1)的随机数

c++ - 手动将整数变量放入字符串中

c++ - 多重集、映射和 HashMap 复杂度

c++ - 基于 vector 获取范围内的项目索引

c++ - 循环时持有对 unique_ptr 的引用

c++ - 如何重现基于随机算法的相同状态

c++ - 我可以使用什么 Mac/iOS/Portable 库来格式化信息以打印到标签纸上?

c++ - 我可以使 GetOpenFileName 返回路径长于 MAX_PATH 吗?

c++ - 类 POD 成员默认初始化与零初始化与无初始化?

php - ramsey/uuid 版本 4 使用 "true"还是伪随机数?