Random number generation

Random number generation is a process by which, often by means of a random number generator (RNG), a sequence of numbers or symbols is generated that cannot be reasonably predicted better than by random chance. This means that the particular outcome sequence will contain some patterns detectable in hindsight but impossible to foresee. True random number generators can be hardware random-number generators (HRNGs), wherein each generation is a function of the current value of a physical environment's attribute that is constantly changing in a manner that is practically impossible to model. This would be in contrast to so-called random number generations done by pseudorandom number generators (PRNGs), which generate pseudorandom numbers that are in fact predetermined—these numbers can be reproduced simply by knowing the initial state of the PRNG and the method it uses to generate numbers.[1] There is also a class of non-physical true random number generators (NPTRNG) that produce true random numbers without an access to a dedicated hardware source, by scavenging entropy that is present in the computer system.[2] See the details in True vs. pseudo-random numbers.
Various applications of randomness have led to the development of different methods for generating random data. Some of these have existed since ancient times, including well-known examples like the rolling of dice, coin flipping, the shuffling of playing cards, the use of yarrow stalks (for divination) in the I Ching, as well as countless other techniques. Because of the mechanical nature of these techniques, generating large quantities of sufficiently random numbers (important in statistics) required much work and time. Thus, results would sometimes be collected and distributed as random number tables.
Several computational methods for pseudorandom number generation exist. All fall short of the goal of true randomness, although they may meet, with varying success, some of the statistical tests for randomness intended to measure how unpredictable their results are (that is, to what degree their patterns are discernible). This generally makes them unusable for applications such as cryptography. However, carefully designed cryptographically secure pseudorandom number generators (CSPRNGS) also exist, with special features specifically designed for use in cryptography.
Practical applications and uses
[edit]Random number generators have applications in gambling, statistical sampling, computer simulation, cryptography, completely randomized design, and other areas where producing an unpredictable result is desirable. Generally, in applications having unpredictability as the paramount feature, such as in security applications, hardware generators are generally preferred over pseudorandom algorithms, where feasible.
Pseudorandom number generators are very useful in developing Monte Carlo-method simulations, as debugging is facilitated by the ability to run the same sequence of random numbers again by starting from the same random seed. They are also used in cryptography – so long as the seed is secret. The sender and receiver can generate the same set of numbers automatically to use as keys.
The generation of pseudorandom numbers is an important and common task in computer programming. While cryptography and certain numerical algorithms require a very high degree of apparent randomness, many other operations only need a modest amount of unpredictability. Some simple examples might be presenting a user with a "random quote of the day", or determining which way a computer-controlled adversary might move in a computer game. Weaker forms of randomness are used in hash algorithms and in creating amortized searching and sorting algorithms.
Some applications that appear at first sight to be suitable for randomization are in fact not quite so simple. For instance, a system that "randomly" selects music tracks for a background music system must only appear random, and may even have ways to control the selection of music: a truly random system would have no restriction on the same item appearing two or three times in succession.
True vs. pseudo-random numbers
[edit]There are two principal methods used to generate random numbers. The first method measures some physical phenomenon that is expected to be random and then compensates for possible biases in the measurement process. Example sources include measuring atmospheric noise, thermal noise, and other external electromagnetic and quantum phenomena. For example, cosmic background radiation or radioactive decay as measured over short timescales represent sources of natural entropy (as a measure of unpredictability or surprise of the number generation process).
The speed at which entropy can be obtained from natural sources is dependent on the underlying physical phenomena being measured. Thus, sources of naturally occurring true entropy are said to be blocking – they are rate-limited until enough entropy is harvested to meet the demand. On some Unix-like systems, including most Linux distributions, the pseudo device file /dev/random will block until sufficient entropy is harvested from the environment.[3] Due to this blocking behavior, large bulk reads from /dev/random, such as filling a hard disk drive with random bits, can often be slow on systems that use this type of entropy source.
The second method uses computational algorithms that can produce long sequences of apparently random results, which are in fact completely determined by a shorter initial value, known as a seed value or key. As a result, the entire seemingly random sequence can be reproduced if the seed value is known. This type of random number generator is often called a pseudorandom number generator. This type of generator typically does not rely on sources of naturally occurring entropy, though it may be periodically seeded by natural sources. This generator type is non-blocking, so they are not rate-limited by an external event, making large bulk reads a possibility.
Standard cryptographic designs take a hybrid approach, using randomness harvested from natural sources to seed a cryptographically secure pseudorandom number generators (CSPRNGs). Hardware random number generators generally produce only a limited number of random bits per second. In order to increase the available output data rate, they are often used to generate the "seed" for a faster PRNG. PRNG also helps with the noise source "anonymization" (whitening out the noise source identifying characteristics) and entropy extraction. With a proper PRNG algorithm selected (cryptographically secure pseudorandom number generator, CSPRNG), the combination can satisfy the requirements of Federal Information Processing Standards and Common Criteria standards.[4]
Generation methods
[edit]Physical methods
[edit]The earliest methods for generating random numbers, such as dice, coin flipping and roulette wheels, are still used today, mainly in games and gambling, as they tend to be too slow for most applications in statistics and cryptography.

Many natural phenomena generate low-level, statistically random "noise" signals, including thermal and shot noise, jitter and metastability of electronic circuits, Brownian motion, and atmospheric noise.[5] Researchers also used the photoelectric effect, involving a beam splitter, other quantum phenomena,[6][7][8][9][10] and even nuclear decay (due to practical considerations the latter, as well as the atmospheric noise, is not viable except for fairly restricted applications or online distribution services).[5] While "classical" (non-quantum) phenomena are not truly random, an unpredictable physical system is usually acceptable as a source of randomness, so the qualifiers "true" and "physical" are used interchangeably.[11]
A hardware random number generator is expected to output near-perfect random numbers ("full entropy").[12] A physical process usually does not have this property, and a practical TRNG typically includes a few blocks:[13]
- a noise source that implements the physical process producing the entropy. Usually this process is analog, so a digitizer is used to convert the output of the analog source into a binary representation;
- a conditioner (randomness extractor) that improves the quality of the random bits;
- health tests. TRNGs are mostly used in cryptographical algorithms that get completely broken if the random numbers have low entropy, so the testing functionality is usually included.
Computational methods
[edit]For performance and security reasons, most random number generators use PRNGs in their construction (this architecture is actually mandated in the industrial standards like NIST SP 800-90A).
A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG),[14] is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG-generated sequence is not truly random, because it is completely determined by an initial value, called the PRNG's seed (which may include truly random values). Although sequences that are closer to truly random can be generated using hardware random number generators, pseudorandom number generators are important in practice for their speed in number generation and their reproducibility.[15]
PRNGs are central in applications such as simulations (e.g. for the Monte Carlo method), electronic games (e.g. for procedural generation), and cryptography. Cryptographic applications require the output not to be predictable from earlier outputs, and more elaborate algorithms, which do not inherit the linearity of simpler PRNGs, are needed.
Good statistical properties are a central requirement for the output of a PRNG. In general, careful mathematical analysis is required to have any confidence that a PRNG generates numbers that are sufficiently close to random to suit the intended use. John von Neumann cautioned about the misinterpretation of a PRNG as a truly random generator, joking that "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."[16]By humans
[edit]Random number generation may also be performed by humans, in the form of collecting various inputs from end users and using them as a randomization source. However, most studies find that human subjects have some degree of non-randomness when attempting to produce a random sequence of e.g., digits or letters. They may alternate too much between choices when compared to a good random generator;[17] thus, this approach is not widely used. However, for the very reason that humans perform poorly in this task, human random number generation can be used as a tool to gain insights into brain functions otherwise not accessible.[18]
Post-processing and statistical checks
[edit]Even given a source of plausible random numbers (perhaps from a quantum mechanically based hardware generator), obtaining numbers which are completely unbiased takes care. In addition, behavior of these generators often changes with temperature, power supply voltage, the age of the device, or other outside interference.
Generated random numbers are sometimes subjected to statistical tests before use to ensure that the underlying source is still working, and then post-processed to improve their statistical properties. An example would be the TRNG9803[19] hardware random number generator, which uses an entropy measurement as a hardware test, and then post-processes the random sequence with a shift register stream cipher. It is generally hard to use statistical tests to validate the generated random numbers. Wang and Nicol[20] proposed a distance-based statistical testing technique that is used to identify the weaknesses of several random generators. Li and Wang[21] proposed a method of testing random numbers based on laser chaotic entropy sources using Brownian motion properties.
Statistical tests are also used to give confidence that the post-processed final output from a random number generator is truly unbiased, with numerous randomness test suites being developed.
Other considerations
[edit]Reshaping the distribution
[edit]Uniform distributions
[edit]Most random number generators natively work with integers or individual bits, so an extra step is required to arrive at the canonical uniform distribution between 0 and 1. The implementation is not as trivial as dividing the integer by its maximum possible value. Specifically:[22][23]
- The integer used in the transformation must provide enough bits for the intended precision.
- The nature of floating-point math itself means there exists more precision the closer the number is to zero. This extra precision is usually not used due to the sheer number of bits required.
- Rounding error in division may bias the result. At worst, a supposedly excluded bound may be drawn contrary to expectations based on real-number math.
The mainstream algorithm, used by OpenJDK, Rust, and NumPy, is described in a proposal for C++'s STL. It does not use the extra precision and suffers from bias only in the last bit due to round-to-even.[24] Other numeric concerns are warranted when shifting this canonical uniform distribution to a different range.[25] A proposed method for the Swift programming language claims to use the full precision everywhere.[26]
Uniformly distributed integers are commonly used in algorithms such as the Fisher–Yates shuffle. Again, a naive implementation may induce a modulo bias into the result, so more involved algorithms must be used. A method that nearly never performs division was described in 2018 by Daniel Lemire,[27] with the current state-of-the-art being the arithmetic encoding-inspired 2021 "optimal algorithm" by Stephen Canon of Apple Inc.[28]
Most 0 to 1 RNGs include 0 but exclude 1, while others include or exclude both.
Other distributions
[edit]Given a source of uniform random numbers, there are a couple of methods to create a new random source that corresponds to a probability density function. One method called the inversion method, involves integrating up to an area greater than or equal to the random number (which should be generated between 0 and 1 for proper distributions). A second method called the acceptance-rejection method, involves choosing an x and y value and testing whether the function of x is greater than the y value. If it is, the x value is accepted. Otherwise, the x value is rejected and the algorithm tries again.[29][30]
As an example for rejection sampling, to generate a pair of statistically independent standard normally distributed random numbers (x, y), one may first generate the polar coordinates (r, θ), where r2~χ22 and θ~UNIFORM(0,2π) (see Box–Muller transform).
Whitening
[edit]The outputs of multiple independent RNGs can be combined (for example, using a bit-wise XOR operation) to provide a combined RNG at least as good as the best RNG used. This is referred to as software whitening.
Computational and hardware random number generators are sometimes combined to reflect the benefits of both kinds. Computational random number generators can typically generate pseudorandom numbers much faster than physical generators, while physical generators can generate true randomness.
Low-discrepancy sequences as an alternative
[edit]Some computations making use of a random number generator can be summarized as the computation of a total or average value, such as the computation of integrals by the Monte Carlo method. For such problems, it may be possible to find a more accurate solution by the use of so-called low-discrepancy sequences, also called quasirandom numbers. Such sequences have a definite pattern that fills in gaps evenly, qualitatively speaking; a truly random sequence may, and usually does, leave larger gaps.
Activities and demonstrations
[edit]The following sites make available random number samples:
- The SOCR resource pages contain a number of hands-on interactive activities and demonstrations of random number generation using Java applets.
- The Quantum Optics Group at the ANU generates random numbers sourced from quantum vacuum. Samples of random numbers are available at their quantum random number generator research page.
- Random.org makes available random numbers that are sourced from the randomness of atmospheric noise.
- The Quantum Random Bit Generator Service at the Ruđer Bošković Institute harvests randomness from the quantum process of photonic emission in semiconductors. They supply a variety of ways of fetching the data, including libraries for several programming languages.
- The Group at the Taiyuan University of Technology generates random numbers sourced from a chaotic laser. Samples of random numbers are available at their physical random number generator service.
Backdoors
[edit]Since much cryptography depends on a cryptographically secure random number generator for key and cryptographic nonce generation, if a random number generator can be made predictable, it can be used as backdoor by an attacker to break the encryption.
The NSA is reported to have inserted a backdoor into the NIST certified cryptographically secure pseudorandom number generator Dual EC DRBG. If for example an SSL connection is created using this random number generator, then according to Matthew Green it would allow NSA to determine the state of the random number generator, and thereby eventually be able to read all data sent over the SSL connection.[31] Even though it was apparent that Dual_EC_DRBG was a very poor and possibly backdoored pseudorandom number generator long before the NSA backdoor was confirmed in 2013, it had seen significant usage in practice until 2013, for example by the prominent security company RSA Security.[32] There have subsequently been accusations that RSA Security knowingly inserted a NSA backdoor into its products, possibly as part of the Bullrun program. RSA has denied knowingly inserting a backdoor into its products.[33]
It has also been theorized that hardware RNGs could be secretly modified to have less entropy than stated, which would make encryption using the hardware RNG susceptible to attack. One such method that has been published works by modifying the dopant mask of the chip, which would be undetectable to optical reverse-engineering.[34] For example, for random number generation in Linux, it is seen as unacceptable to use Intel's RDRAND hardware RNG without mixing in the RDRAND output with other sources of entropy to counteract any backdoors in the hardware RNG, especially after the revelation of the NSA Bullrun program.[35][36]
In 2010, a U.S. lottery draw was rigged by the information security director of the Multi-State Lottery Association (MUSL), who surreptitiously installed backdoor malware on the MUSL's secure RNG computer during routine maintenance.[37] During the hacks the man won a total amount of $16,500,000 over multiple years.
See also
[edit]- Flipism
- League of entropy
- List of random number generators
- PP (complexity)
- Procedural generation
- Randomized algorithm
- Random password generator
- Random variable, contains a chance-dependent value
References
[edit]- ^ Lugrin, Thomas (2023), Mulder, Valentin; Mermoud, Alain; Lenders, Vincent; Tellenbach, Bernhard (eds.), "Random Number Generator", Trends in Data Protection and Encryption Technologies, Cham: Springer Nature Switzerland, pp. 31–34, doi:10.1007/978-3-031-33386-6_7, ISBN 978-3-031-33386-6
- ^ Schindler 2008, p. 18.
- ^ – Linux Programmer's Manual – Special Files from Manned.org
- ^ Saarinen, Newell & Marshall 2020.
- ^ a b Sunar 2009, p. 56.
- ^ Herrero-Collantes & Garcia-Escartin 2017, p. 8.
- ^ Jacak, Marcin M.; Jóźwiak, Piotr; Niemczuk, Jakub; Jacak, Janusz E. (2021). "Quantum generators of random numbers". Scientific Reports. 11 (1): 16108. Bibcode:2021NatSR..1116108J. doi:10.1038/s41598-021-95388-7. PMC 8352985. PMID 34373502.
- ^ Ma, Xiongfeng; Yuan, Xiao; Cao, Zhu; Qi, Bing; Zhang, Zhen (2016). "Quantum random number generation". npj Quantum Information. 2 (1): 16021. arXiv:1510.08957. Bibcode:2016npjQI...216021M. doi:10.1038/npjqi.2016.21.
- ^ Kollmitzer, Christian; Petscharnig, Stefan; Suda, Martin; Mehic, Miralem (2020). "Quantum Random Number Generation". Quantum Random Number Generation: Theory and Practice. Springer International Publishing. pp. 11–34. doi:10.1007/978-3-319-72596-3_2. ISBN 978-3-319-72596-3.
- ^ Mannalath, Mishra & Pathak 2023.
- ^ Herrero-Collantes & Garcia-Escartin 2017, p. 4.
- ^ Turan et al. 2018, p. 64.
- ^ Turan et al. 2018, p. 6.
- ^ Barker, Elaine; Barker, William; Burr, William; Polk, William; Smid, Miles (July 2012). "Recommendation for Key Management" (PDF). NIST Special Publication 800-57. NIST. doi:10.6028/NIST.SP.800-57p1r3. Retrieved 19 August 2013.
- ^ "Pseudorandom number generators". Khan Academy. Retrieved 2016-01-11.
- ^ Von Neumann, John (1951). "Various techniques used in connection with random digits" (PDF). National Bureau of Standards Applied Mathematics Series. 12: 36–38. Archived from the original (PDF) on 28 November 2022.
- ^ W. A. Wagenaar (1972). "Generation of random sequences by human subjects: a critical survey of the literature". Psychological Bulletin. 77 (1): 65–72. CiteSeerX 10.1.1.211.9085. doi:10.1037/h0032060.
- ^ W. A. Wagenaar (1972). "Generation of random sequences by human subjects: a critical survey of the literature". Psychological Bulletin. 77 (1): 65–72. CiteSeerX 10.1.1.211.9085. doi:10.1037/h0032060.
- ^ Dömstedt, B. (2009). "TRNG9803 True Random Number Generator". Manufacturer: www.TRNG98.se.
- ^ Wang, Yongge (2014). "Statistical Properties of Pseudo Random Sequences and Experiments with PHP and Debian OpenSSL". Computer Security - ESORICS 2014. Lecture Notes in Computer Science. Vol. 8712. Heidelberg: Springer LNCS. pp. 454–471. doi:10.1007/978-3-319-11203-9_26. ISBN 978-3-319-11202-2.
- ^ Li, Pu; Yi, Xiaogang; Liu, Xianglian; Wang, Yuncai; Wang, Yongge (2016-07-11). "Brownian motion properties of optoelectronic random bit generators based on laser chaos". Optics Express. 24 (14): 15822–15833. Bibcode:2016OExpr..2415822L. doi:10.1364/OE.24.015822. ISSN 1094-4087. PMID 27410852.
- ^ Goualard, F. (2020). "Generating Random Floating-Point Numbers by Dividing Integers: A Case Study". Computational Science – ICCS 2020. ICCS. Lecture Notes in Computer Science. Vol. 12138. pp. 15–28. doi:10.1007/978-3-030-50417-5_2. ISBN 978-3-030-50416-8. PMC 7302591. S2CID 219889587.
- ^ Campbell, Taylor R. (2014). "Uniform random floats: How to generate a double-precision floating-point number in [0, 1] uniformly at random given a uniform random source of bits". Retrieved 4 September 2021.
- ^ "A new specification for std::generate_canonical". www.open-std.org.
- ^ Goualard, Frédéric (July 2021). "Drawing random floating-point numbers from an interval". HAL. Retrieved 4 September 2021.
- ^ NevinBR. "[stdlib] Floating-point random-number improvements by NevinBR · Pull Request #33560 · apple/swift". GitHub.
- ^ Lemire, Daniel (23 February 2019). "Fast Random Integer Generation in an Interval". ACM Transactions on Modeling and Computer Simulation. 29 (1): 1–12. arXiv:1805.10941. doi:10.1145/3230636. S2CID 44061046.
- ^ "An optimal algorithm for bounded random integers by stephentyrone · Pull Request #39143 · apple/swift". GitHub.
- ^ The MathWorks. "Common generation methods". Retrieved 2024-09-08.
- ^ The Numerical Algorithms Group. "G05 – Random Number Generators" (PDF). NAG Library Manual, Mark 23. Retrieved 2012-02-09.
- ^ matthew Green (2013-09-18). "The Many Flaws of Dual_EC_DRBG".
- ^ Matthew Green (2013-09-20). "RSA warns developers not to use RSA products".
- ^ "We don't enable backdoors in our crypto products, RSA tells customers". Ars Technica. 2013-09-20.
- ^ "Researchers can slip an undetectable trojan into Intel's Ivy Bridge CPUs". Ars Technica. 2013-09-18.
- ^ Theodore Ts'o. "I am so glad I resisted pressure from Intel engineers to let /dev/random rely only on the RDRAND instruction". Google Plus.
- ^ Theodore Ts'o (17 September 2013). "Re: [PATCH] /dev/random: Insufficient of entropy on many architectures". LWN.
- ^ Nestel, M.L. (July 7, 2015). "Inside the Biggest Lottery Scam Ever". The Daily Beast. Retrieved July 10, 2015.
Sources
[edit]- Saarinen, Markku-Juhani O.; Newell, G. Richard; Marshall, Ben (2020-11-09). Building a Modern TRNG: An Entropy Source Interface for RISC-V (PDF). New York, NY, USA: ACM. doi:10.1145/3411504.3421212. Archived from the original on 2021-03-16. Retrieved 2023-09-09.
{{cite conference}}: CS1 maint: bot: original URL status unknown (link) - Schindler, Werner (2008). "Random Number Generators for Cryptographic Applications". In Koc, C.K. (ed.). Cryptographic Engineering. Boston, MA: Springer US. pp. 5–23. doi:10.1007/978-0-387-71817-0_2. ISBN 978-0-387-71817-0. Retrieved 2024-08-24.
- Turan, Meltem Sönmez; Barker, Elaine; Kelsey, John; McKay, Kerry A; Baish, Mary L; Boyle, Mike (2018). NIST SP800-90B: Recommendation for the entropy sources used for random bit generation (Report). Gaithersburg, MD: National Institute of Standards and Technology. doi:10.6028/nist.sp.800-90b.
- Sunar, Berk (2009). "True Random Number Generators for Cryptography". Cryptographic Engineering. Boston, MA: Springer US. pp. 55–73. doi:10.1007/978-0-387-71817-0_4. ISBN 978-0-387-71816-3.
- Herrero-Collantes, Miguel; Garcia-Escartin, Juan Carlos (2017-02-22). "Quantum random number generators". Reviews of Modern Physics. 89 (1) 015004. American Physical Society (APS). arXiv:1604.03304. Bibcode:2017RvMP...89a5004H. doi:10.1103/revmodphys.89.015004. ISSN 0034-6861.
- Mannalath, Vaisakh; Mishra, Sandeep; Pathak, Anirban (2023). "A Comprehensive Review of Quantum Random Number Generators: Concepts, Classification and the Origin of Randomness". Quantum Information Processing. 22 (12): 439. arXiv:2203.00261. Bibcode:2023QuIP...22..439M. doi:10.1007/s11128-023-04175-y.
Further reading
[edit]- Donald Knuth (1997). "Chapter 3 – Random Numbers". The Art of Computer Programming. Vol. 2: Seminumerical algorithms (3 ed.).
- L'Ecuyer, Pierre (2017). "History of Uniform Random Number Generation" (PDF). Proceedings of the 2017 Winter Simulation Conference. IEEE Press. pp. 202–230.
- L'Ecuyer, Pierre (2012). "Random Number Generation" (PDF). In J. E. Gentle; W. Haerdle; Y. Mori (eds.). Handbook of Computational Statistics: Concepts and Methods. Handbook of Computational Statistics (second ed.). Springer-Verlag. pp. 35–71. doi:10.1007/978-3-642-21551-3_3. hdl:10419/22195. ISBN 978-3-642-21550-6.
- Kroese, D. P.; Taimre, T.; Botev, Z.I. (2011). "Chapter 1 – Uniform Random Number Generation". Handbook of Monte Carlo Methods. New York: John Wiley & Sons. p. 772. ISBN 978-0-470-17793-8.
- Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007). "Chapter 7. Random Numbers". Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8.
- NIST SP800-90A, B, C series on random number generation Archived 2017-09-12 at the Wayback Machine
- M. Tomassini; M. Sipper; M. Perrenoud (October 2000). "On the generation of high-quality random numbers by two-dimensional cellular automata". IEEE Transactions on Computers. 49 (10): 1146–1151. Bibcode:2000ITCmp..49.1146T. doi:10.1109/12.888056. S2CID 10139169.
External links
[edit]- RANDOM.ORG True Random Number Service
- Quantum random number generator at ANU
- Random and Pseudorandom on In Our Time at the BBC
- jRand a Java-based framework for the generation of simulation sequences, including pseudorandom sequences of numbers
- Random number generators in NAG Fortran Library
- Randomness Beacon at NIST, broadcasting full entropy bit-strings in blocks of 512 bits every 60 seconds. Designed to provide unpredictability, autonomy, and consistency.
- A system call for random numbers: getrandom(), a LWN.net article describing a dedicated Linux system call
- Statistical Properties of Pseudo Random Sequences and Experiments with PHP and Debian OpenSSL
- Random Sequence Generator based on Avalanche Noise
- Cryptographically Enhanced PRNG
- Random Number Generator