# 随机数生成

随机数生成是指产生数字或比特序列的过程，这些数字或比特序列缺乏可用于预测的规律。它为密码学、[蒙特卡洛](https://www.edgepedia.org/zh/monte-carlo)模拟、概率游戏、数值建模和工业测试提供原材料，由两种截然不同的成分构成：真正不可预测的物理过程，以及输出仅表面上看似随机的确定性算法。<sup>[1](https://arxiv.org/abs/1103.4381)</sup><sup> • </sup><sup>[2](https://968t.com/en/articles/random-number-generator-guide/)</sup>

| 关键事实 | 详情 |
|---|---|
| 两大类别 | 真随机数生成器利用电子热噪声等物理现象；伪随机数生成器使用数学算法，而密码学生成器则将算法与熵源相结合。<sup>[2](https://968t.com/en/articles/random-number-generator-guide/)</sup> |
| 最早的计算机生成器 | 约翰·冯·诺伊曼（John von Neumann）提出了中间平方法，即将一个数的平方的中间数字作为下一个值，该方法在1949年的一次会议上提出（von Neumann, 1951）；一份历史记述将这一提议追溯到1946年。<sup>[3](https://www.sciencedirect.com/topics/mathematics/random-number)</sup><sup> • </sup><sup>[4](https://zufallszahlen-generator.de/geschichte-der-zufallszahlengeneratoren)</sup> |
| 熵的度量 | 概率为 p<sub>i</sub> 的随机变量 X 的不确定性为 H(X) = − ∑<sub>i=1</sub><sup>n</sup> p<sub>i</sub> log p<sub>i</sub>；美国国家标准与技术研究院（NIST）的 SP 800-90B 使用最小熵作为熵源的度量。<sup>[5](https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-22r1a.pdf)</sup><sup> • </sup><sup>[6](https://www.nist.gov/publications/recommendation-entropy-sources-used-random-bit-generation)</sup> |
| NIST框架 | SP 800-90B（2018年1月10日）规定了熵源的设计与验证；其熵源与 SP 800-90A 中的 DRBG 机制相结合，按照 SP 800-90C 构建随机比特生成器。<sup>[6](https://www.nist.gov/publications/recommendation-entropy-sources-used-random-bit-generation)</sup> |
| 测试的局限 | NIST SP 800-22 指出，没有任何一组统计测试能够绝对证明某个生成器适用于特定应用；统计测试不能替代密码分析。<sup>[7](https://csrc.nist.gov/pubs/sp/800/22/r1/upd1/final)</sup> |
| 量子硬件 | 弗劳恩霍夫IPMS（Fraunhofer IPMS）的 Q-Dice 量子随机数生成器以 4.1 Gbit/s 的速率输出随机性，并依据德国联邦信息安全局（BSI）的 AIS 20/31 标准获得 EAL 3 和 PTG 3 认证。<sup>[8](https://www.ipms.fraunhofer.de/en/press-media/press/2026/Quantum-Random-Number-Generator-QRNG.html)</sup> |

## 真随机与伪随机生成

真随机数生成器（TRNG）测量一个结果无法复现的物理过程：电路中电子运动涨落产生的电子热噪声是一种标准来源，例如用于硬件安全模块。<sup>[2](https://968t.com/en/articles/random-number-generator-guide/)</sup> 密码密钥生成恰恰需要这种不可预测性，因为能够复现数据的攻击者就能复现密钥。<sup>[9](https://arxiv.org/abs/1510.01234)</sup>

伪随机数生成器（PRNG）则运行确定性算法。NIST 对密码学形式的术语是确定性随机比特生成器（DRBG）；SP 800-90A 修订版1（2015年6月）推荐了包括哈希 DRBG、HMAC DRBG 和 CTR DRBG 在内的 DRBG 构造，所有这些构造都必须由熵源提供种子。<sup>[10](https://xlinux.nist.gov/dads/HTML/pseudorandomNumberGen.html)</sup> 安全要求是：在不知道输入的情况下，输出不可预测。<sup>[7](https://csrc.nist.gov/pubs/sp/800/22/r1/upd1/final)</sup>

这两类生成器服务于不同目的。模拟需要统计质量，游戏需要公平性，密码协议需要攻击者无法复现的不可预测性；真随机生成器往往不是蒙特卡洛计算所需要的，因为它是非确定性的，会使运行复现变得复杂。<sup>[2](https://968t.com/en/articles/random-number-generator-guide/)</sup>

## 历史

**中间平方与同余。** 冯·诺伊曼的中间平方法取一个 n 位整数，将其平方，然后取平方数的中间部分作为下一个随机整数；该方法容易陷入极短的循环，这促使人们设计更好的方案。<sup>[3](https://www.sciencedirect.com/topics/mathematics/random-number)</sup> 随后出现了基于模大整数 m 的线性递推的线性同余生成器（LCG）；它们提供了均匀性、独立性和相对较大的周期。<sup>[3](https://www.sciencedirect.com/topics/mathematics/random-number)</sup>

**梅森旋转算法及后续设计。** 较新的系列在追求质量的同时也追求速度：在 1 GHz 双核 Cortex-A7 ARM CPU 上的测试中，PCG-XSL-RR 64/32 的性能是 32 位[梅森旋转算法](https://www.edgepedia.org/zh/mersenne-twister)的 2.07 倍。<sup>[12](https://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf)</sup>

## 标准与测试

NIST 的 SP 800-90 系列将密码学随机比特生成分为三部分。SP 800-90B 于2018年1月10日由梅尔特姆·索内兹·图兰（Meltem Sonmez Turan）、伊莱恩·巴克（Elaine Barker）、约翰·凯尔西（John Kelsey）、克里·麦凯（Kerry McKay）、玛丽·L·贝什（Mary L. Baish）和[迈克·博伊尔](https://www.edgepedia.org/zh/mike-boyle)（Mike Boyle）发布，规定了熵源的设计原则和要求、熵源所测量的噪声源、条件化函数、健康测试以及用于验证熵源的测试，并以最小熵作为熵的度量。<sup>[6](https://www.nist.gov/publications/recommendation-entropy-sources-used-random-bit-generation)</sup> 这些熵源旨在与 SP 800-90A 的 DRBG 机制相结合，按照 SP 800-90C 的规定构建随机比特生成器。<sup>[6](https://www.nist.gov/publications/recommendation-entropy-sources-used-random-bit-generation)</sup>

统计测试是互补性的检查。NIST SP 800-22 修订版1 提供了适用于密码学应用的随机和伪随机数生成器的统计测试套件，使用 p 值和假设检验，包括近似熵测试等测试项目。<sup>[7](https://csrc.nist.gov/pubs/sp/800/22/r1/upd1/final)</sup><sup> • </sup><sup>[13](https://csrc.nist.rip/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf)</sup> 该文件本身界定了此类测试所能证明的边界：这些测试可能是判断生成器是否适合某一应用的第一步，但没有任何一组统计测试能够绝对证明一个生成器合格，统计测试也不能替代密码分析。<sup>[7](https://csrc.nist.gov/pubs/sp/800/22/r1/upd1/final)</sup> 因此，用于调校生成器的有限测试集应着重关注其已知弱点。<sup>[3](https://www.sciencedirect.com/topics/mathematics/random-number)</sup>

## 量子随机数生成器

量子随机数生成器（QRNG）从量子过程中获取随机性，这些过程在原则上是不可预测的，而不仅仅是难以建模。它们是一个活跃的标准化领域：国际标准化组织（ISO）正在发布量子随机数生成器技术的概述（IEC/ISO TR 63744），中国的国家标准 GB/T 45240-2025 涵盖了设备无关量子随机数生成器的通用要求。<sup>[14](https://www.iso.org/standard/94932.html?browse=tc)</sup><sup> • </sup><sup>[15](https://std.samr.gov.cn/gb/search/gbDetailed?id=2D5D2D0FF71C31E0E06397BE0A0A126F)</sup>

欧洲电信标准化协会（ETSI）于2026年9月24日宣布的技术报告 ETSI TR 104 171 针对可能在整个生命周期中损害 QRNG 输出质量的弱点：对量子熵源进行建模和验证、应用适当的随机性提取，以及在运行过程中监测熵质量以检测漂移、偏差和硬件故障。该报告还概述了未来的标准化优先事项，包括认证与日志记录协议、更强的安全认证模型，以及将 QRNG 与后量子密码学相结合的指南。<sup>[16](https://www.etsi.org/newsroom/press-releases/etsis-identifies-limitations-of-quantum-random-number-generators/)</sup>

商用设备正达到数据中心规模。弗劳恩霍夫IPMS的 Q-Dice 以19英寸机架系统和在线“熵即服务”平台的形式，从量子真空涨落中生成随机数，额定速率为 4.1 Gbit/s，并依据德国联邦信息安全局（BSI）的 AIS 20/31 标准获得[评估保证级别](https://www.edgepedia.org/zh/evaluation-assurance-level)3和物理真随机数生成器级别 PTG 3 的认证。<sup>[8](https://www.ipms.fraunhofer.de/en/press-media/press/2026/Quantum-Random-Number-Generator-QRNG.html)</sup><sup> • </sup><sup>[17](https://www.techradar.com/pro/it-looks-like-an-old-pc-but-this-bleeding-edge-server-may-well-save-us-from-hackers-causing-chaos-in-a-post-quantum-computing-world-4-1gb-s-rackable-quantum-random-number-generator-brings-entropy-to-the-data-center)</sup>

**经认证的完美随机性。** 即便是最好的传统生成器也可能带有微小偏差，这些偏差在日常使用中无害，但在密码学中可被利用，因为安全性取决于不可预测性。[苏黎世联邦理工学院](https://www.edgepedia.org/zh/eth-zurich)（ETH Zurich）由物理学教授[雷纳托·伦纳](https://www.edgepedia.org/zh/renato-renner)（Renato Renner）和[安德烈亚斯·瓦尔拉夫](https://www.edgepedia.org/zh/andreas-wallraff)（Andreas Wallraff）领导的一个团队在2026年报告称，他们利用纠缠超导量子比特克服了这一缺陷，并将该成果描述为首次经认证实现的完美随机性。<sup>[18](https://www.livescience.com/physics-mathematics/quantum-physics/physicists-achieve-perfect-randomness-for-the-first-time-ever)</sup>

## 应用

随机数是众多领域的一种资源：密码学（经典与量子）、通过蒙特卡洛方法进行的概率计算、数值模拟、工业测试与标签、概率游戏以及科学研究。<sup>[1](https://arxiv.org/abs/1103.4381)</sup> 在模拟中，生成过程常被转移到并行硬件上；一种 GPU 实现达到了约 18 MSamples/s 的吞吐量，而高能物理蒙特卡洛软件包中使用的 PRNG 也已针对该场景进行了专门审查。<sup>[19](https://arxiv.org/abs/1101.1846)</sup><sup> • </sup><sup>[20](https://arxiv.org/abs/1003.1898)</sup>

## References

1. [Quantum random number generators and their use in cryptography, arXiv](https://arxiv.org/abs/1103.4381)
2. [The Complete Guide to Random Number Generation, 968T Toolbox](https://968t.com/en/articles/random-number-generator-guide/)
3. [Random Number, ScienceDirect Topics](https://www.sciencedirect.com/topics/mathematics/random-number)
4. [Geschichte der Zufallszahlengeneratoren](https://zufallszahlen-generator.de/geschichte-der-zufallszahlengeneratoren)
5. [NIST SP 800-22 Rev. 1a, A Statistical Test Suite for Random and Pseudorandom Number Generators](https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-22r1a.pdf)
6. [Recommendation for the Entropy Sources Used for Random Bit Generation, NIST SP 800-90B](https://www.nist.gov/publications/recommendation-entropy-sources-used-random-bit-generation)
7. [NIST SP 800-22 Rev. 1, A Statistical Test Suite for Random and Pseudorandom Number Generators for Cryptographic Applications, CSRC](https://csrc.nist.gov/pubs/sp/800/22/r1/upd1/final)
8. [Fraunhofer IPMS unveils Q-Dice: Quantum Random Number Generator](https://www.ipms.fraunhofer.de/en/press-media/press/2026/Quantum-Random-Number-Generator-QRNG.html)
9. [Hardware Random Number Generator for cryptography, arXiv](https://arxiv.org/abs/1510.01234)
10. [Pseudo-random number generator, NIST Dictionary of Algorithms and Data Structures](https://xlinux.nist.gov/dads/HTML/pseudorandomNumberGen.html)
11. [History of uniform random number generation, ResearchGate](https://www.researchgate.net/publication/318318619_History_of_uniform_random_number_generation)
12. [PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation](https://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf)
13. [NIST SP 800-22 Rev. 1a (mirror copy)](https://csrc.nist.rip/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf)
14. [IEC/ISO AWI TR 63744, Quantum technologies — Overview of quantum random number generator, ISO](https://www.iso.org/standard/94932.html?browse=tc)
15. [GB/T 45240-2025, General requirements for device-independent quantum random number generators, 全国标准信息公共服务平台](https://std.samr.gov.cn/gb/search/gbDetailed?id=2D5D2D0FF71C31E0E06397BE0A0A126F)
16. [ETSI helps manufacturers improve quantum random number generators, ETSI](https://www.etsi.org/newsroom/press-releases/etsis-identifies-limitations-of-quantum-random-number-generators/)
17. [4.1 Gb/s rackable quantum random number generator brings entropy to the data center, TechRadar](https://www.techradar.com/pro/it-looks-like-an-old-pc-but-this-bleeding-edge-server-may-well-save-us-from-hackers-causing-chaos-in-a-post-quantum-computing-world-4-1gb-s-rackable-quantum-random-number-generator-brings-entropy-to-the-data-center)
18. [Physicists achieve 'perfect randomness' for the first time ever, Live Science](https://www.livescience.com/physics-mathematics/quantum-physics/physicists-achieve-perfect-randomness-for-the-first-time-ever)
19. [Using graphics processing units to generate random numbers, arXiv](https://arxiv.org/abs/1101.1846)
20. [Pseudo-random number generators for Monte Carlo simulations on Graphics Processing Units, arXiv](https://arxiv.org/abs/1003.1898)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms › Pseudorandomness and hashing algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/random-number-generation

English original: https://www.edgepedia.org/random-number-generation
