/dev/urandom是否适合仿真? [英] Is `/dev/urandom` suitable for simulation purpose?

查看:56
本文介绍了/dev/urandom是否适合仿真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在类unix的系统中使用普通C语言,从/dev/urandom 中获取 fread 是提取高质量随机字节的最简单方法.我需要运行一个模拟,该模拟每秒需要大约10k 32位随机数,并且可能要运行几天.为此可以使用/dev/urandom 吗?熵池耗尽后,随机字节的质量如何?

It seems that using plain C in unix-like systems, fread from /dev/urandom is the simplest way to extract high quality random bytes. I need to run a simulation that needs about 10k 32-bit random numbers per second, and it may run for several days. Is /dev/urandom okay to use for this purpose? How is the quality of random bytes from here when the entropy pool is depleted?

edit_1

虽然我现在在笔记本电脑中针对/dev/urandom 运行3个并行的顽固测试,但我得到了以下有趣的内容.测试尚未完成.

While I'm now running 3 parallel diehard tests for /dev/urandom in my laptop, I got the following interesting lines. The test isn't yet complete.

#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
 diehard_parking_lot|   0|     12000|     100|0.99573896|   WEAK
        diehard_sums|   0|       100|     100|0.00116464|   WEAK
          sts_serial|   7|    100000|     100|0.99996076|   WEAK

推荐答案

/dev/urandom 的基础实现中是CSPRNG,其输出池的最大周期为小于2 ^(26 * 32)− 1 ,然后将其送入SHA-1以产生/dev/urandom 的输出.因此, urandom 显然可以产生所需的随机数,但是它不能为您提供可重复的结果-您将不得不缓存自己得到的序列.

In the underlying implementation of /dev/urandom is a CSPRNG, the output pool of which has a maximal period of less than 2^(26∗32) − 1, which is then fed into SHA-1 to produce output for /dev/urandom. As such, urandom can obviously produce the amount of random numbers you want, however it can not offer you reproducible results - you will have to cache the sequence you get yourself.

您不必担心估计熵池耗尽时会发生什么,/dev/urandom 将输出您要求的任何内容.urandom(4)手册页所说的理论攻击"是不存在.(问题"是对熵估计"的巨大误解)

You do not have to worry about what happens when the entropy pool is estimated to be depleted, /dev/urandom will output whatever you request of it. The "theoretical attacks" the urandom(4) man page speaks of are nonexistent. (the "issue" is a huge misunderstanding of what "entropy estimation" is)

存在许多其他可重复播种的PRNG,它们的周期较长: C ++ xorshift PRNG,等等.您应该可以使任何PRNG都适合您的用途.

Many other PRNGs with large periods exist which reproducible seeding: the Mersenne Twister in C++, xorshift PRNGs, etc. You should be able to adapt any PRNG to the distribution which is suitable for your purposes.

这篇关于/dev/urandom是否适合仿真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆