Picking A, C and M for Linear congruential generator
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Linear Congruential Generators (LCGs) are a popular method for generating pseudo-random numbers. They owe their simplicity to a straightforward formula:
where: • is the next random number. • is the current random number. • , , and are non-negative integer constants. • is the modulus. • .
To ensure that an LCG behaves as desired, particularly that it produces numbers with a long period and good statistical properties, choosing appropriate values for , , and is crucial.
Selecting the Modulus (M)
- Bit Length: Choose as a power of 2 or a large prime number. A common choice is
$M = 2^\{31\}$ or $M = 2^\{32\}$due to hardware efficiency. - Periodicity: The maximum period of an LCG is when , , and are selected properly.
Selecting the Multiplier (A)
- Full Period Criterion: For full period LCGs, a common criterion is that: • for every prime dividing . •
$A \equiv 1 \pmod\{4\}$ if $M$is a multiple of 4. - Simple Choices: Use an increment based on the formula when is a power of 2. However, test empirically for randomness.
Example
If , a suitable multiplier can be which satisfies .
Selecting the Increment (C)
- Co-prime Criteria: should be co-prime to . This ensures the maximum period when the other conditions are met.
- Avoid Zero: When , choose non-zero to avoid sequential repetition.
Example
For and , a possible increment is . Since 3 is co-prime to 16 (common factors are only 1), it is valid.
Table of Key Points
| Component | Selection Criteria | Examples |
| Prefer powers of 2 or large primes. | , , | |
Ensure $A \equiv 1 \pmod\{p\}$ for each prime dividing M. | $A=5$ for | |
| Co-prime with . | for |
Further Considerations
• Seed Selection (): The seed must be chosen carefully to prevent predictable sequences. It is not bound by the co-prime rule. • Empirical Testing: Once parameters are chosen, empirical testing is essential to evaluate randomness quality using tests like the chi-square or Kolmogorov-Smirnov tests. • Modern Practices: Despite their historical popularity, LCGs are typically replaced in modern applications by more complex, cryptographically secure generators for applications requiring high-quality randomness.
In summary, the correct choice of , , and is crucial for the LCG to function effectively. While LCGs have limitations, when configured correctly, they serve well for applications requiring consistent and reproducible pseudo-random numbers.

