All Topics  
Random number generation

 

   Email Print
   Bookmark   Link






 

Random number generation



 
 
A random number generator (often abbreviated as RNG) is a computational
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
 or physical device designed to generate a sequence of number
Number

A number is a mathematical object used in counting and measurement. A notational symbol which represents a number is called a Numeral system, but in common usage the word number is used for both the abstract object and the symbol, as well as for the numeral for the number....
s or symbols that lack any pattern, i.e. appear random. Hardware-based systems for random number generation are widely used, but often fall short of this goal, though they may meet some of the statistical tests for randomness intended to ensure that they do not have any easily discernible patterns.






Discussion
Ask a question about 'Random number generation'
Start a new discussion about 'Random number generation'
Answer questions from other users
Full Discussion Forum



Encyclopedia


A random number generator (often abbreviated as RNG) is a computational
Computer

A computer is a machine that manipulates Data according to a list of Code .The first devices that resemble modern computers date to the mid-20th century , although the computer concept and various machines similar to computers existed earlier....
 or physical device designed to generate a sequence of number
Number

A number is a mathematical object used in counting and measurement. A notational symbol which represents a number is called a Numeral system, but in common usage the word number is used for both the abstract object and the symbol, as well as for the numeral for the number....
s or symbols that lack any pattern, i.e. appear random. Hardware-based systems for random number generation are widely used, but often fall short of this goal, though they may meet some of the statistical tests for randomness intended to ensure that they do not have any easily discernible patterns. Methods for generating random results have existed since ancient times, including dice
Dice

A die is a small polyhedron object, usually cubic, used for generating Statistical randomnesss or other symbols. This makes dice suitable as gambling devices, especially for craps or sic bo, or for use in non-gambling tabletop games....
, coin flipping
Coin flipping

Coin flipping or coin tossing is the practice of throwing a coin in the air to resolve a dispute between two parties or otherwise choose between two alternatives....
, the shuffling of playing card
Playing card

A playing card is a piece of specially prepared heavy paper, thin card, or thin plastic, figured with distinguishing motifs and used as one of a set for playing card games....
s, the use of yarrow
Yarrow

Achillea millefolium or Yarrow is a flowering plant in the family Asteraceae, native to the Northern Hemisphere....
 stalks (by divination) in the I Ching
I Ching

The I Ching , or ?Y? Jing? ; also called Classic of Changes or Book of Changes is one of the oldest of the Chinese classic texts....
, and many other techniques.

The many applications of randomness
Applications of randomness

Randomness has many uses in gambling, divination, statistics, cryptography, art, etc.Note that these uses may have different requirements when it comes to statistical randomness or unpredictability, which in turn leads to different randomization methods....
 have led to many different methods for generating random
Randomness

Randomness is a lack of order, purpose, Causality, or predictability. Randomness as defined by Aristotle is the situation, when a choice is to be made which has no logical component by which to determine or make the choice ....
 data. These methods may vary as to how unpredictable or statistically random
Statistical randomness

A numeric sequence is said to be statistically random when it contains no recognizable patterns or regularities; sequences such as the results of an ideal dice, or the digits of pi exhibit statistical randomness....
 they are, and how quickly they can generate random numbers.

Before the advent of computational random number generators, generating large amounts of sufficiently random numbers (important in statistics) required a lot of work. Results would sometimes be collected and distributed as random number table
Random number table

Random number tables have been used in statistics for tasks such as selected randomness samples. This was much more effective than manually selecting the random samples ....
s.

A growing number of government-run lotteries
Lottery

A lottery is a form of gambling which involves the drawing of lots for a prize. Some governments outlaw it, while others endorse it to the extent of organizing a national lottery....
, and lottery games, are using RNGs instead of more traditional drawing methods, such as using ping-pong or rubber balls.

Physical methods

The earliest methods for generating random numbers — dice
Dice

A die is a small polyhedron object, usually cubic, used for generating Statistical randomnesss or other symbols. This makes dice suitable as gambling devices, especially for craps or sic bo, or for use in non-gambling tabletop games....
, coin flipping
Coin flipping

Coin flipping or coin tossing is the practice of throwing a coin in the air to resolve a dispute between two parties or otherwise choose between two alternatives....
, roulette
Roulette

Roulette is a casino and gambling game named after the French language word meaning "small wheel". In the game, players may choose to place bets on either a number, a range of numbers, the color red or black, or whether the number is odd or even....
 wheels — are still used today, mainly in games
Game

A game is a structured wiktionary:activity, usually undertaken for enjoyment and sometimes used as an educational tool. Games are distinct from Manual labour, which is usually carried out for wiktionary:remuneration, and from art, which is more concerned with the expression of ideas....
 and gambling as they tend to be too slow for applications in statistics and cryptography.

Some physical phenomena, such as thermal noise in Zener diode
Zener diode

A Zener diode is a type of diode that permits electric current in the forward direction like a normal diode, but also in the reverse direction if the voltage is larger than the breakdown voltage known as "Zener knee voltage" or "Zener voltage"....
s appear to be truly random and can be used as the basis for hardware random number generator
Hardware random number generator

In computing, a hardware random number generator is an apparatus that generates random numbers from a physical process. Such devices are often based on microscopic phenomena such as thermal noise or the photoelectric effect or other quantum phenomena....
s. However, many mechanical phenomena feature asymmetries and systematic bias
Systematic bias

In metrology, dynamical systems theory, computational mechanics, and statistics, a systematic bias is a bias of a measurement system or estimate method, which leads to systematic errors, namely produces readings or results which are consistently too high or too low, relative to a given actual value of the measured or estimated variable....
es that make their outcomes not truly random. The many successful attempts to exploit such phenomena by gamblers, especially in roulette
Roulette

Roulette is a casino and gambling game named after the French language word meaning "small wheel". In the game, players may choose to place bets on either a number, a range of numbers, the color red or black, or whether the number is odd or even....
 and blackjack
Blackjack

Blackjack is the most widely played casino game banking game in the world. Much of blackjack's popularity is due to the mix of chance with elements of skill, and the publicity that surrounds card counting ....
 are testimony to these effects.

There are several imaginative sources of random numbers online. A common technique is to run a hash function
Hash function

A hash function is any algorithm or function which converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an array index into an array....
 against a frame of a video stream from an unpredictable source. This technique was used by Lavarand
Lavarand

Lavarand was Silicon Graphics' name for its hardware random number generator that worked by taking pictures of the patterns made by the floating material in lava lamps, extracting random data from the pictures, and using the result to seed a pseudo-random number generator....


which used images of a number of lava lamp
Lava lamp

A lava lamp is a Novelties used for decoration rather than illumination; the slow chaos theory rise and fall of randomly-shaped blobs of wax is suggestive of lava, hence the name....
s. Lithium Technologies
Lithium Technologies

Lithium Technologies is an online customer support and brand loyalty company based in Emeryville, California, California. Some of the company's services include Internet forum, chat room, instant messaging, and a wide range of online customer interaction tools....
 uses a camera pointed at the sky on a windy and cloudy day. Random.org has a more obvious approach of listening to atmospheric noise. Details about how they turn their input into random numbers can be found on their respective sites.

Completely randomized design
Completely randomized design

In the design of experiments, completely randomized designs are for studying the effects of one primary factor without the need to take other nuisance factors into account....
 falls within the category of true random number generation. The generation of true random numbers outside the computer environment is based on the theory of entropy
Information entropy

In information theory, entropy is a measure of the uncertainty associated with a random variable. The term by itself in this context usually refers to the Shannon entropy, which quantifies, in the sense of an expected value, the self-information contained in a message, usually in units such as bits....
. Sources of entropy include nuclear decay and atmospheric conditions. uses radioactive decay, while uses radio noise to generate randomness.

Another common entropy source is the behavior of human users of the system, if such users exist. While humans are not considered good randomness generators upon request, they generate random behavior quite well in the context of playing mixed strategy games. The utilization of Human gameplay entropy
Entropy

In many branches of science, entropy is a measure of the disorder of a system. The concept of entropy is particularly notable as it is applied across physics, information theory and mathematics....
 for Randomness Generation was studied by Ran Halprin and Moni Naor
Moni Naor

Moni Naor is an Israelis computer scientist, currently a professor at the Weizmann Institute of Science. Naor received his Ph.D. in 1989 at the University of California, Berkeley....
, see

Computational methods

Pseudo-random number generators (PRNGs) are algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
s that can automatically create long runs (for example, millions of numbers long) with good random properties but eventually the sequence repeats exactly (or the memory usage grows without bound). One of the most common PRNG is the linear congruential generator
Linear congruential generator

A linear congruential generator represents one of the oldest and best-known pseudorandom number generator algorithms. The theory behind them is easy to understand, and they are easily implemented and fast....
, which uses the recurrence

to generate numbers. The maximum number of numbers the formula can produce is the modulus
Modulus

Modulus may refer to:*Modulus , a formal product of places of a number field*Modulus of continuity, a way to measure the smoothness of a function...
, m. To avoid certain non-random properties of a single linear congruential generator
Linear congruential generator

A linear congruential generator represents one of the oldest and best-known pseudorandom number generator algorithms. The theory behind them is easy to understand, and they are easily implemented and fast....
, several such random number generators with slightly different values of the multiplier coeffient a are typically used in parallel, with a "master" random number generator that selects from among the several different generators.

A simple pen-and-paper method for generating random numbers is the so-called middle square method suggested by John Von Neumann
John von Neumann

John von Neumann was a Hungarian American mathematician who made major contributions to a vast range of fields, including set theory, functional analysis, quantum mechanics, ergodic theory, continuous geometry, economics and game theory, computer science, numerical analysis, hydrodynamics , and statistics, as well as many other mathematical...
. While simple to implement, its output is of poor quality.

Most computer programming languages include functions or library routines that purport to be random number generators. They are often designed to provide a random byte or word, or a floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
 number uniformly distributed
Uniform distribution (continuous)

In probability theory and statistics, the continuous uniform distribution is a family of probability distributions such that for each member of the family, all interval s of the same length on the distribution's support are equally probable....
 between 0 and 1.

Such library functions often have poor statistical properties and some will repeat patterns after only tens of thousands of trials. They are often initialized using a computer's real time clock as the seed. These functions may provide enough randomness for certain tasks (for example video games) but are unsuitable where high-quality randomness is required, such as in cryptographic applications, statistics or numerical analysis. Much higher quality random number sources are available on most operating systems; for example /dev/random
/dev/random

In Unix-like operating systems, /dev/random is a special file that serves as a true random number generator or as a pseudorandom number generator....
 on various BSD flavors, Linux, Mac OS X, IRIX, and Solaris, or CryptGenRandom
CryptGenRandom

CryptGenRandom is a CSPRNG function that is included in Microsoft's Cryptographic Application Programming Interface. In Win32 programs, Microsoft recommends its use anywhere random number generation is needed....
 for Microsoft Windows.

Practical applications and uses of random numbers


Random number generators have applications in gambling
Gambling

Gambling is the wikt:wager#Verb of money or something of material Value on an event with an uncertain outcome with the primary intent of winning additional money and/or material goods....
, statistical sampling, computer simulation
Computer simulation

A computer simulation, a computer model or a computational model is a computer program, or network of computers, that attempts to simulation an abstract model of a particular system....
, cryptography
Cryptography

Cryptography is the practice and study of hiding information. In modern times cryptography is considered a branch of both mathematics and computer science and is affiliated closely with information theory, computer security and engineering....
, and other areas where a random number is useful in producing an unpredictable result.

Note that, in general, where unpredictability is paramount--such as in security applications-- hardware generators are generally preferred, where feasible, over pseudo-random algorithms.

Random number generators are very useful in developing Monte Carlo method
Monte Carlo method

Monte Carlo methods are a class of computational algorithms that rely on repeated random sampling to compute their results. Monte Carlo methods are often used when computer simulation physics and mathematics systems....
 simulations as debugging
Debugging

Debugging is a methodical process of finding and reducing the number of computer bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected....
 is facilitated by the ability to run the same sequence of random numbers again by starting from the same random seed
Random seed

A random seed is a number used to initialize a pseudorandom number generator.The choice of a good random seed is crucial in the field of computer security....
. They are also used in cryptography
Cryptography

Cryptography is the practice and study of hiding information. In modern times cryptography is considered a branch of both mathematics and computer science and is affiliated closely with information theory, computer security and engineering....
 so long as the seed is secret. Sender and receiver can generate the same set of numbers automatically to use as keys.

The generation of pseudo-random 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 also closely associated with hash algorithms and in creating amortized
Amortization

Amortization or amortisation is the process of increasing, or accounting for, an amount over a period of time. The word comes from Middle English amortisen to kill, alienate in mortmain, from Anglo-French amorteser, alteration of amortir, from Vulgar Latin admortire to kill, from Latin ad- + mort-, mors death....
 searching
Search algorithm

In computer science, a search algorithm, broadly speaking, is an algorithm that takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions....
 and sorting algorithm
Sorting algorithm

In computer science and mathematics, a sorting algorithm is an algorithm that puts elements of a List in a certain Total order. The most-used orders are numerical order and lexicographical order....
s.

Some applications which 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 to be random; a true random system would have no restriction on the same item appearing two or three times in succession.

Activities and demonstrations

The SOCR
SOCR

The Statistics Online Computational Resource is a suite of online tools and interactive aids for hands-on learning and teaching concepts in statistical analysis and probability developed at the University of California, Los Angeles....
 resource pages contain a number of of random number generation using Java applets.

"True" random numbers vs. pseudorandom numbers


There are two principal methods used to generate random numbers. One measures some physical phenomenon that is expected to be random and then compensates for possible biases in the measurement process. The other uses computational algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
s that produce long sequences of apparently random results, which are in fact completely determined by a shorter initial value, known as a seed or key
Key (cryptography)

In cryptography, a key is a piece of information that determines the functional output of a cryptographic algorithm or cipher. Without a key, the algorithm would have no result....
. The latter type are often called pseudorandom number generator
Pseudorandom number generator

A pseudorandom number generator is an algorithm for generating a sequence of numbers that approximates the properties of random numbers. The sequence is not truly random in that it is completely determined by a relatively small set of initial values, called the PRNG's state. Although sequences that are closer to truly random can be gen...
s.

A "random number generator" based solely on deterministic computation cannot be regarded as a "true" random number generator, since its output is inherently predictable. John von Neumann
John von Neumann

John von Neumann was a Hungarian American mathematician who made major contributions to a vast range of fields, including set theory, functional analysis, quantum mechanics, ergodic theory, continuous geometry, economics and game theory, computer science, numerical analysis, hydrodynamics , and statistics, as well as many other mathematical...
 famously said "Anyone who uses arithmetic methods to produce random numbers is in a state of sin." How to distinguish a "true" random number from the output of a pseudo-random number generator is a very difficult problem. However, carefully chosen pseudo-random number generators can be used instead of true random numbers in many applications. Rigorous statistical analysis of the output is often needed to have confidence in the algorithm.

Generating random numbers from physical processes

There is general agreement that, if there are such things as "true" random numbers, they are most likely to be found by looking at physical processes which are, as far as is known, unpredictable.

A physical random number generator can be based on an essentially random atomic or subatomic physical phenomenon whose unpredictability can be traced to the laws of quantum mechanics
Quantum mechanics

Quantum mechanics is a set of principles underlying the most fundamental known description of all physical systems at the microscopic scale . Notable amongst these principles are both a dual wave-like and particle-like behavior of matter and radiation, and prediction of probabilities in situations where classical physics predicts certaintie...
. An example of this are the Atari 8-bit computers
Atari 8-bit family

The Atari 8-bit family is a series of 8-bit home computers manufactured from 1979 to 1992. All are based on the MOS Technology MOS Technology 6502 central processing unit and were the first home computers designed with custom coprocessor chips, giving them the most powerful graphic, sound and I/O subsystems of any 8 bit machine of their time...
, which used electronic noise
Electronic noise

Electronic noise is an unwanted signal characteristic of all electronics electrical circuit. Depending on the circuit, the noise put out by electronic devices can vary greatly....
 from an analog circuit to generate true random numbers. Other examples include radioactive decay
Radioactive decay

Radioactive decay is the process in which an unstable atomic nucleus loses energy by emitting ionizing particles and radiation. This decay, or loss of energy, results in an atom of one type, called the parent nuclide transforming to an atom of a different type, called the daughter nuclide....
, thermal noise, shot noise
Shot noise

Shot noise is a type of electronic noise that occurs when the finite number of particles that carry energy, such as electrons in an electronic circuit or photons in an optical device, is small enough to give rise to detectable statistical fluctuations in a measurement....
 and clock drift
Clock drift

Clock drift refers to several related phenomena where a clock does not run at the exact right speed compared to another clock. That is, after some time the clock "drifts apart" from the other clock....
. Even lava lamp
Lava lamp

A lava lamp is a Novelties used for decoration rather than illumination; the slow chaos theory rise and fall of randomly-shaped blobs of wax is suggestive of lava, hence the name....
s have been used by the Lavarand
Lavarand

Lavarand was Silicon Graphics' name for its hardware random number generator that worked by taking pictures of the patterns made by the floating material in lava lamps, extracting random data from the pictures, and using the result to seed a pseudo-random number generator....
 generator.

To provide a degree of randomness intermediate between specialized hardware on the one hand and algorithmic generation on the other, some security related computer software requires the user to input a lengthy string of mouse movements, or keyboard input.

Post-processing and statistical checks

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. And a software bug in a pseudo-random number routine, or a hardware bug in the hardware it runs on, may be similarly difficult to detect.

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.

See also: Statistical randomness
Statistical randomness

A numeric sequence is said to be statistically random when it contains no recognizable patterns or regularities; sequences such as the results of an ideal dice, or the digits of pi exhibit statistical randomness....


Other considerations

Random numbers uniformly distributed between 0 and 1 can be used to generate random numbers of any desired distribution by passing them through the inverse cumulative distribution function
Cumulative distribution function

In probability theory and statistics, the cumulative distribution function or just distribution function, completely describes the probability distribution of a real-valued random variable X....
(CDF) of the desired distribution. Inverse CDFs are also called quantile functions
Quantile function

In probability theory, a quantile function of aprobability distribution is the inverse function F −1 of its cumulative distribution function F....
. To generate a pair of statistically independent
Statistical independence

In probability theory, to say that two event s are independent intuitively means that the occurrence of one event makes it neither more nor less probable that the other occurs....
 standard normally distributed
Normal distribution

The normal distribution, also called the Gaussian distribution, is an important family of continuous probability distributions, applicable in many fields....
 random numbers (x, y), one may first generate the polar coordinates (r, ?), where r~?22
Chi-square distribution

In probability theory and statistics, the chi-square distribution is one of the most widely used theoretical probability distributions in inferential statistics, e.g., in statistical significance tests....
 and ?~UNIFORM(0,2p)
Uniform distribution (continuous)

In probability theory and statistics, the continuous uniform distribution is a family of probability distributions such that for each member of the family, all interval s of the same length on the distribution's support are equally probable....
 (see Box-Muller transform
Box-Muller transform

A Box-Muller transform is a method of generating pairs of statistical independence standard normal distribution random numbers, given a source of uniform distribution random numbers....
).

Some 0 to 1 RNGs include 0 but exclude 1, while others include or exclude both.

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
Hardware random number generator

In computing, a hardware random number generator is an apparatus that generates random numbers from a physical process. Such devices are often based on microscopic phenomena such as thermal noise or the photoelectric effect or other quantum phenomena....
.

Computational and hardware random number generators are sometimes combined to reflect the benefits of both kinds. Computational random number generators can typically generate pseudo-random numbers much faster than physical generators, while physical generators can generate true randomness.

Low-discrepancy sequences as an alternative

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
Monte Carlo method

Monte Carlo methods are a class of computational algorithms that rely on repeated random sampling to compute their results. Monte Carlo methods are often used when computer simulation physics and mathematics systems....
. For such problems, it may be possible to find a more accurate solution by the use of so-called low-discrepancy sequence
Low-discrepancy sequence

In mathematics, a low-discrepancy sequence is a sequence with the property that for all values of N, its subsequence x1, ..., xN has a low discrepancy of a sequence....
s, 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.

Generation from a probability distribution

There are a couple of methods to generate a random number based on a probability density function
Probability density function

In mathematics, a probability density function is a function that represents a probability distribution in terms of integrals.Formally, a probability distribution has density ƒ, if ƒ is a non-negative Lebesgue integration function such that the probability of the interval [ab] is given by...
. These methods involve transforming a uniform random number in some way. Because of this, these methods work equally well in generating both pseudo-random and true random numbers. 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
Rejection sampling

In mathematics, rejection sampling is a technique used to generate observations from a probability distribution. It is also commonly called the acceptance-rejection method or "accept-reject algorithm"....
, 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.

See also

  • Randomization
    Randomization

    Randomization is the process of making something random; this means:* Generating a random permutation of a sequence .* Selecting a random sample of a population ....
  • Randomized algorithm
    Randomized algorithm

    A randomized algorithm or probabilistic algorithm is an algorithm which employs a degree of randomness as part of its logic. The algorithm typically uses Uniform distribution bits as an auxiliary input to guide its behavior, in the hope of achieving good performance in the "average case" over all possible choices of random bits....
  • Hardware random number generator
    Hardware random number generator

    In computing, a hardware random number generator is an apparatus that generates random numbers from a physical process. Such devices are often based on microscopic phenomena such as thermal noise or the photoelectric effect or other quantum phenomena....
  • List of random number generators
    List of random number generators

    Computer random number generators are important in mathematics, cryptography and gambling. This list includes all common types, regardless of quality....
  • Random number generator attack
    Random number generator attack

    The security of cryptographic systems depends on some secret data that is known to authorized persons but unknown and unpredictable to others. To achieve this unpredictability, some randomization is typically employed....
  • Random password generator
    Random password generator

    A random password generator is Computer software program or Computer hardware device that takes input from a random or pseudo-random number generator and automatically generates a password....
  • Randomness
    Randomness

    Randomness is a lack of order, purpose, Causality, or predictability. Randomness as defined by Aristotle is the situation, when a choice is to be made which has no logical component by which to determine or make the choice ....
  • Procedural generation
    Procedural generation

    Procedural generation is a widely used term in the production of media, indicating the possibility to create content on the fly rather than prior to distribution....