random - 随机和随机之间的区别

标签 random prng

我正在尝试找出 /dev/random/dev/urandom 文件之间的差异

  1. /dev/random/dev/urandom 之间有什么区别?
  2. 我应该什么时候使用它们?
  3. 什么时候不应该使用它们?

最佳答案

使用/dev/random可能需要等待结果,因为它使用所谓的熵池,其中随机数据目前可能不可用。

/dev/urandom 返回用户请求的尽可能多的字节,因此它的随机性比 /dev/random 低。

可以从手册页中读取:

随机

When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered.

随机

A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current unclassified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead.

出于加密目的,您应该真正使用 /dev/random 因为它返回的数据的性质。出于安全考虑,可能的等待应被视为可接受的权衡,IMO。

当您需要快速随机数据时,您当然应该使用/dev/urandom

来源:Wikipedia页,man页面

关于random - 随机和随机之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23712581/

相关文章:

c - Galois LFSR - 如何指定输出位数

javascript - 快速轻松地从文件夹中选择一个随机文件

c++ - rand() 即使使用 srand( time(NULL) ) 也不起作用

r - 关于随机数生成器的可能问题

python - 如何在循环中不断更新张量的值

python - 如何从 Python 中的双峰分布生成 n 个随机值?

c - 如何使用指针通过被调用函数在 main 中编辑数组

c++ - [0..1[中的随机实数使用 Mersenne Twister

CUDA - 为傻瓜使用 CURAND 库

c# - 为什么我对随机数生成器进行的 parking 场测试会产生不好的结果?