Research 8 -- Most common PRG


Random number generators are important in many fields, including physics, engineering, mathematics, computer science and cryptographic applications (where they play a crucial role in some situations). Random number generators can be divided in two main classes: true random number generators (TRNG), which typically make use of an unpredictable physical mean to generate numbers (e.g. atmospheric noises);  and pseudorandom number generators (PRNG), which uses a mathematical deterministic algorithm, computed on an initial value (aka the seed) to generate the random numbers.

Even though it should be obvious, is worth to insist on the fact that the choice of the random number generator strictly depend on what the generated numbers will be used for. For instance, not every PRG is good for cryptographic applications. Such a PRG should pass all the statistical tests another required condition is that an adversary, without knowing the seed, cannot distinguish its output from a truly random source with non-negligible probability.
Some non-secure random number generators can be constructed from any block cipher using CTR mode whereas some example of cryptographically secure PRG are the Blum-Micali algorithm, the Blum Blum Shub and the Naor-Reingold pseudorandom function.

That being said, let's consider random number generators that aren't good for cryptography but can be used in several application like statistics. There are several techniques used to generate a random number on a probability density function and they typically consists into modifying a uniform random number.

- Inversion method: integrating up to an area greater than or equal to the random number (which should belong to the range [0,1]).

- Acceptance-rejection: choose x and y and test whether the function of x is greater than the y value. If it is, the x value is accepted; otherwise it's rejected and the algorithm tried again.


Another common generator is the Box-Muller transform, which is a pseudorandom sampling method for generating pairs of independent, standard, normally distributed (zero mean, unit variance) random numbers, given a source of uniformly distributed random numbers. The method is expressed in two forms: the basic form takes two samples from the uniform distribution on the interval [0, 1] and maps them to two normally distributed samples whereas the polar form takes two samples from [-1, +1] and maps them to two samples without the use of sine or cosine functions.

Suppose U1 and U2 are independent samples chosen from the uniform distribution on the unit interval (0, 1). Let






Then Z0 and Z1 are independent random variables with a standard normal distribution.

Box-Mueller Transform -- Polar Form

The polar form is most widely used, in part due to its inclusion in an important series of books on algorithms and numerical analysis (Numerical Recipes).
Given u and v uniformly distributed in the closed interval [-1, +1], set s = R2 = u2 + v2.
If s = 0 or s ≥ 1, discard u and v, and try another pair.

Because u and v are uniformly distributed and because only points within the unit circle have been admitted, the values of s will be uniformly distributed in the open interval (0, 1), too.










Other PRGs


  • Lehmer generator (and LFSR, LCG)
  • Mersenne Twister 
The latter takes a seed of w bits as input and outputs integers in the range [0, 2w-1] using an algorithm which is based on a matrix linear recurrence over a finite binary field F2. The Mersenne Twister is the most used general-purpose PRNG, it's the default random number generators for several software systems including Python, Ruby and PHP.

Commenti

Post popolari in questo blog

Welford Algorithm

Research 6 - Derivation of Chebyshev's inequality and its application to prove the (weak) LLN

Research 7 -- Central Limit Theorem, LLN, and most common probability distributions