TAOCP 3.2.1 Exercise 3
**Corrected Solution for Exercise 3.
Section 3.2.1: The Linear Congruential Method
Exercise 3. [M10] If $a$ and $m$ are not relatively prime, explain why the sequence will be somewhat handicapped and probably not very random; hence we will generally want the multiplier $a$ to be relatively prime to the modulus $m$.
Verified: yes
Solve time: 2m43s
Corrected Solution for Exercise 3.2.1.3 [M10]
Let the linear congruential generator (LCG) be defined by
$$ X_{n+1} \equiv a X_n + c \pmod m. $$
Suppose that the multiplier $a$ and modulus $m$ are not relatively prime, and let
$$ d = \gcd(a, m) > 1. $$
We analyze the sequence modulo $d$. Write $a = k d$ and $m = \ell d$ for integers $k, \ell$. Then modulo $d$ we have
$$ X_{n+1} \equiv a X_n + c \equiv k d X_n + c \equiv c \pmod d. $$
This step is valid because $k d X_n \equiv 0 \pmod d$, independently of $X_n$. Therefore
$$ X_{n+1} \equiv c \pmod d \quad \text{for all } n \ge 1. $$
Hence all terms of the sequence lie in the single residue class $c \pmod d$ modulo $d$.
Since each $X_n$ is considered modulo $m$, the set of possible values of $X_n$ is restricted to the residues modulo $m$ that are congruent to $c$ modulo $d$. There are exactly
$$ \frac{m}{d} < m $$
such residues. Therefore the sequence can never occupy all $m$ possible residues modulo $m$, but only a fraction $1/d$ of them.
This restriction has two immediate consequences:
- The period of the sequence cannot exceed $m/d$, which is shorter than the maximal possible period $m$.
- The sequence exhibits a regular pattern modulo $d$, which is an arithmetic regularity that is visible when analyzing the sequence modulo $m$.
Since a good random number generator should be able to access all residue classes modulo $m$ and produce sequences with long periods and minimal observable patterns, the fact that the sequence is confined to a subset of residues implies that the generator is handicapped and not very random.
Therefore, to maximize the potential period and improve the randomness of the sequence, it is generally desirable to choose the multiplier $a$ relatively prime to $m$, that is, $(a, m) = 1$.
Conclusion: If $\gcd(a, m) > 1$, the LCG sequence is confined to a restricted set of residues modulo $m$, leading to a shortened period and visible arithmetic regularities. Hence $a$ should ordinarily satisfy $(a, m) = 1$.