Английская Википедия:Combined linear congruential generator

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description A combined linear congruential generator (CLCG) is a pseudo-random number generator algorithm based on combining two or more linear congruential generators (LCG). A traditional LCG has a period which is inadequate for complex system simulation.[1] By combining two or more LCGs, random numbers with a longer period and better statistical properties can be created.[1] The algorithm is defined as:[2] <math display="block">X_i \equiv \left( \sum_{j=1}^k (-1)^{j-1}Y_{i,j} \right)\pmod{m_1 - 1}</math> where:

  • <math> m_1</math> is the "modulus" of the first LCG
  • <math> Y_{i,j}</math> is the ith input from the jth LCG
  • <math> X_i </math> is the ith generated random integer

with: <math display="block"> R_i \equiv \begin{cases}

 X_i/m_1  & \text{for }  X_i >  0 \\
 (m_1-1)/m_1 & \text{for } X_i=0
 \end{cases}

</math> where <math>R_{i}</math> is a uniformly distributed random number between 0 and 1.

Derivation

If Wi,1, Wi,2, ..., Wi,k are any independent, discrete, random-variables and one of them is uniformly distributed from 0 to m1 − 2, then Zi is uniformly distributed between 0 and m1 − 2, where:[2] <math display="block"> Z_i= \left( \sum_{j=1}^k W_{i,j} \right) \pmod {m_1-1} </math>

Let Xi,1, Xi,2, ..., Xi,k be outputs from k LCGs. If Wi,j is defined as Xi,j − 1, then Wi,j will be approximately uniformly distributed from 0 to mj − 1.[2] The coefficient "(−1)j−1" implicitly performs the subtraction of one from Xi,j.[1]

Properties

The CLCG provides an efficient way to calculate pseudo-random numbers. The LCG algorithm is computationally inexpensive to use.[3] The results of multiple LCG algorithms are combined through the CLCG algorithm to create pseudo-random numbers with a longer period than is achievable with the LCG method by itself.[3]

The period of a CLCG is the least common multiple of the periods of the individual generators, which are one less than the moduli. Since all the moduli are odd primes, the periods are even and thus share at least a common divisor of 2, but if the moduli are chosen so that 2 is the greatest common divisor of each pair, this will result in a period of:[1] <math display="block"> P = \frac{(m_1-1)(m_2-1)\cdots(m_k-1)}{2^{k-1}} </math>

Example

The following is an example algorithm designed for use in 32-bit computers:[2] <math display="block"> k=2 </math> LCGs are used with the following properties: <math display="block"> \begin{align} a_1 & =40014 & a_2 & =40692 \\ m_1 & =2147483563 & m_2 & =2147483399 \\ c_1 & =0 & c_2 & = 0 \end{align} </math>

The CLCG algorithm is set up as follows: Шаблон:Ordered list The maximum period of the two LCGs used is calculated using the formula:[1] <math display="block">(m-1)</math> This equates to 2.1×109 for the two LCGs used.

This CLCG shown in this example has a maximum period of: <math display="block"> (m_1-1)(m_2-1)/2 \approx 2.3 \times 10^{18}</math> This represents a tremendous improvement over the period of the individual LCGs. It can be seen that the combined method increases the period by 9 orders of magnitude.

Surprisingly the period of this CLCG may not be sufficient for all applications.[1] Other algorithms using the CLCG method have been used to create pseudo-random number generators with periods as long as Шаблон:Val.[4][5][6]

The former of the two generators, using b = 40,014 and m = 2,147,483,563, is also used by the Texas Instruments TI-30X IIS scientific calculator.

See also

References

External links