简体   繁体   English

简单的真正随机数生成器

[英]Simple truly random number generator

There is a lot of research going on related to generating "truly" random numbers.有很多与生成“真正”随机数相关的研究正在进行中。

There is a very simple method, invented long time ago.有一个很简单的方法,很久以前发明的。 The method is attributed to von Neumann [1] .该方法归功于冯诺依曼[1]

In the most simple form it can be thought of as generating random bits out of a biased source of 0s or 1s.在最简单的形式中,它可以被认为是从 0 或 1 的偏置源中生成随机位。 Given that probability of a sequence 01 is the same as 10, one can use 01 - to represent the truly random "0" and 10 as a truly random "1" bit (the 00 and 11 combinations are simply discarded).鉴于序列 01 的概率与 10 相同,可以使用 01 - 将真正随机的“0”和 10 表示为真正随机的“1”位(00 和 11 的组合被简单地丢弃)。

Pretty straightforward.很简单。 Can anyone point why such a method doesn't generate a random sequence (and thus solve the problem of generating random numbers on computers)?谁能指出为什么这种方法不会生成随机序列(从而解决在计算机上生成随机数的问题)?

Let me explain what "random" and "truly random" mean.让我解释一下“随机”和“真正随机”是什么意思。 "Random" simply means the numbers are identically distributed and chosen independently of everything else (that is, the numbers are iid). “随机”只是意味着数字是相同分布的,并且独立于其他所有内容进行选择(即,数字是 iid)。 And "truly random" simply means iid and uniform (see also Frauchiger et al. 2013.)而“真正随机”仅仅意味着 iid 和统一(另见 Frauchiger et al. 2013。)

If the source of input bits are iid but have a bias, then the von Neumann method will remove this bias — the numbers remain iid but are now unbiased, namely, each number will be 0 or 1 with equal probability.如果输入位的来源是 iid 但有偏差,那么冯诺依曼方法将消除这种偏差——数字保持 iid 但现在是无偏差的,即每个数字都将是 0 或 1 的概率相等。 In general, if the source numbers weren't iid (more specifically, exchangeable [Peres 1992]) to begin with, the von Neumann method won't make those numbers "truly random";一般来说,如果源数字不是 iid(更具体地说,可交换[Peres 1992]),则冯诺依曼方法不会使这些数字“真正随机”; even von Neumann (1951) assumes "independence of successive tosses [of the coin]".甚至冯诺依曼 (1951) 也假设“连续抛[硬币] 的独立性”。 The von Neumann method is one of a host of randomness extractors available (and I discuss some of them ), and this discussion applies to these other extractors just as well as the von Neumann method.冯诺依曼方法是众多可用的随机抽取器之一(我讨论了其中的一些),这个讨论适用于这些其他抽取器,就像冯诺依曼方法一样。

In any case, the distinction between "pseudorandom" and "truly random" numbers is not what applications care about (and you didn't really specify what kind of application you have in mind).在任何情况下,“伪随机”和“真正随机”数字之间的区别并不是应用程序关心的(并且您没有真正指定您想到的应用程序类型)。 Instead, in general:相反,一般来说:

  • Security applications care whether the numbers are hard to guess;安全应用程序关心数字是否难以猜测; in this case, only a cryptographic RNG can achieve this requirement (even one that relies on a pseudorandom number generator).在这种情况下,只有加密 RNG 才能满足这一要求(即使是依赖于伪随机数生成器的)。 A Python example is the secrets module or random.SystemRandom . Python 示例是secrets模块或random.SystemRandom
  • Scientific simulations care whether the numbers behave like independent uniform random numbers, and often care whether the numbers are reproducible at a later time.科学模拟关心这些数字的行为是否像独立的均匀随机数,并且通常关心这些数字在以后是否可重现。 A Python example is numpy.random.Generator . Python 示例是numpy.random.Generator

REFERENCES:参考:

  • Frauchiger, D., Renner, R., Troyer, M., "True randomness from realistic quantum devices", 2013. Frauchiger, D.、Renner, R.、Troyer, M.,“真实量子设备的真实随机性”,2013 年。
  • von Neumann, J., "Various techniques used in connection with random digits", 1951. von Neumann, J.,“与随机数字相关的各种技术”,1951 年。
  • Peres, Y., " Iterating von Neumann's procedure for extracting random bits ", Annals of Statistics 1992,20,1, p. Peres, Y.,“迭代冯诺依曼提取随机位的过程”,统计年鉴 1992,20,1, p. 590-597. 590-597。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM