# TAOCP 3.2.1 The Linear Congruential Method

> Study guide to TAOCP 3.2.1 The Linear Congruential Method. The classic generator X_{n+1} = (aX_n + c) mod m. Knuth covers how to choose the modulus, the…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 3.2.1 The Linear Congruential Method: The classic generator X_{n+1} = (aX_n + c) mod m. Budget about 8 hours; do exercises 3.2.1-2, 3.2.1.1-6 and 3.2.1.1-9.

Knuth covers how to choose the modulus, the exact conditions on a and c for the longest possible period, and the notion of potency that rules out multipliers that are technically fine but bad in practice.

## Key facts {#key-facts}

- Week 65 of 145 on the cracked.guide path, in [TAOCP Vol 2: Seminumerical Algorithms](https://cracked.guide/taocp/volume-2).
- Time budget: about 8 hours.
- 49 exercises in the section, rated 10 to 40; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 3.2.1-2, 3.2.1.1-6, 3.2.1.1-9, 3.2.1.2-6, 3.2.1.2-7 and 3.2.1.3-8.
- Before you start: 1.2.4 Integer Functions and Elementary Number Theory and 3.1 Introduction.
- Terms it teaches: [LCG](https://cracked.guide/glossary/linear-congruential-generator).

## Week 65 goals {#objectives}

By the end of week 65 you can:

- Compute the next values of a small linear congruential sequence by hand.
- Explain the conditions on a, c and m that give full period.
- Recognize why low bits of a power-of-two LCG are weak.

## This week's steps {#steps}

- Read §3.2.1 The Linear Congruential Method: Read 3.2.1.1 (modulus), 3.2.1.2 (multiplier) and 3.2.1.3 (potency).
- Work the exercises (8 picked): Start with Ex 3.2.1-2, Ex 3.2.1.1-6, Ex 3.2.1.1-9; log what you solve below.
- Write down one thing you'd explain to someone: A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

## Exercises {#exercises}

This section has 49 exercises, rated 10 to 40, and Knuth marks 16 of them with the triangle for recommended. Counts cover 3.2.1 itself (exercises 1-5) and its subsections 3.2.1.1 Choice of modulus (14), 3.2.1.2 Choice of multiplier (22) and 3.2.1.3 Potency (8); picks are numbered by subsection. The multiplier exercises in 3.2.1.2 are the heart of the week; do those with a calculator or a few lines of code next to you.

Worth your time:

- 3.2.1-2 (rated M20, recommended): If a and m are coprime the seed always comes back. A first taste of why multipliers must be units.
- 3.2.1.1-6 (rated 20, recommended): Swap addition for subtraction in the recurrence and decide whether anything really changes.
- 3.2.1.1-9 (rated M25, recommended): Compute a*x mod m in a language without double-length products, without overflow. The trick behind most portable LCG code.
- 3.2.1.1-11 (rated M30): Push exercise 9 further: evaluate a*x mod m for any multiplier using only small safe operations. The stretch.
- 3.2.1.2-3 (rated 13): Full-period condition for a power-of-ten modulus, specialized from the main theorem. Quick check that you can apply it.
- 3.2.1.2-6 (rated 20, recommended): Find every full-period multiplier for one specific modulus by factoring it.
- 3.2.1.2-7 (rated M23, recommended): Pin down the tail length and period of an arbitrary congruential sequence, not just the full-period case.
- 3.2.1.3-8 (rated M26, recommended): Explain why a generator with low potency fails a simple triples test. The same failure that sank famous real-world generators.

## Why it matters {#why}

LCGs are still inside many standard libraries and games, and knowing their weaknesses (low bits with short periods, patterns in higher dimensions) saves you from subtle simulation bugs.

## Before you start {#before}

- 1.2.4 Integer Functions and Elementary Number Theory
- 3.1 Introduction

## How to approach it {#approach}

Read 3.2.1.1 (modulus), 3.2.1.2 (multiplier) and 3.2.1.3 (potency). Write an LCG with a small modulus like 16 or 64 and print the full sequence to see the period theorem in action. Then print the lowest bit of a power-of-two-modulus LCG and watch it alternate.

## Common traps {#traps}

- Using the low bits of a power-of-two LCG. They have tiny periods.
- Assuming full period means good quality. It does not; the spectral test (3.3.4) is about that.

## Links {#links}

- [Knuth's TAOCP page (editions, errata, MIX/MMIX)](https://www-cs-faculty.stanford.edu/~knuth/taocp.html)
- [Vol 2 errata (plain text, from Knuth)](https://www-cs-faculty.stanford.edu/~knuth/err2.textxt)
- [Wikipedia: Linear congruential generator](https://en.wikipedia.org/wiki/Linear_congruential_generator)
- [Hacker News: Linear Congruential Generators](https://news.ycombinator.com/item?id=8488621)

---

Source: https://cracked.guide/guide/knuth-w048-1
cracked.guide: A free, dated 145-week path to getting genuinely cracked at programming.
