# TAOCP 3.1 Introduction

> Study guide to TAOCP 3.1 Introduction. What "random numbers" means for a computer, why truly random sources are awkward, and a tour of early attempts at…

Updated October 20, 2026.

## Summary {#summary}

TAOCP 3.1 Introduction: What "random numbers" means for a computer, why truly random sources are awkward, and a tour of early attempts at generating pseudorandom numbers, including the middle-square method and why many ad hoc generators fail badly. Budget about 3 hours; do exercises 1, 3 and 5.

## Key facts {#key-facts}

- Week 64 of 145 on the cracked.guide path, in [TAOCP Vol 2: Seminumerical Algorithms](https://cracked.guide/taocp/volume-2).
- Time budget: about 3 hours.
- 23 exercises in the section, rated 10 to M48; the guide picks 8.
- Picked exercises with Knuth's triangle for recommended: 1, 7, 11 and 12.
- Before you start: vol 1 chapter 1 math.

## Week 64 goals {#objectives}

By the end of week 64 you can:

- Explain why a complicated procedure need not produce random numbers.
- Trace the middle-square method on a four-digit seed.
- Recognize why any generator with finite state must eventually cycle.

## This week's steps {#steps}

- Read §3.1 Introduction: Implement the middle-square method and watch it fall into a short cycle.
- Work the exercises (8 picked): Start with Ex 1, Ex 3, Ex 5; 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 23 exercises, rated 10 to M48, and Knuth marks 5 of them with the triangle for recommended. Short tracing questions about the middle-square method sit next to a run of M exercises on random mappings. Do the quick ones, then spend real time on the cycle-detection pair (6 and 7): those algorithms show up in real code.

Worth your time:

- 1 (rated 20, recommended): Judge several physical ways of getting a random digit. Sharpens what you actually mean by random.
- 3 (rated 10): One step of the middle-square method by hand.
- 5 (rated 15): Argue why any generator of this kind must eventually repeat, before computing anything.
- 6 (rated M21): Show that a sequence X(n+1) = f(X(n)) is eventually periodic, and find its cycle using almost no memory. This is Floyd's tortoise-and-hare; implement it.
- 7 (rated M21, recommended): Brent's cycle detection with powers of two. Implement it next to exercise 6 and compare function evaluations.
- 8 (rated 23): Exhaustively analyze two-digit middle-square. A small program makes the fate of every seed visible.
- 11 (rated M26, recommended): Probability that a random mapping with a random seed has no repeats for a while. Birthday-paradox thinking.
- 12 (rated M31, recommended): Average cycle length and tail length for a random mapping. The stretch; ties into rho-style factoring later in 4.5.4.

## Why it matters {#why}

Simulations, games, load testing, hashing and cryptography all depend on random numbers. This section is a warning against inventing your own generator.

## Before you start {#before}

- Vol 1 chapter 1 math

## How to approach it {#approach}

Implement the middle-square method and watch it fall into a short cycle. That one experiment teaches the whole section. Read Knuth's story of his own "super-random" generator failing; it is a great lesson in humility.

## Common traps {#traps}

- Believing that complicated means random. The section's whole point is that it does not.

## 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: Pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator)
- [Wikipedia: Middle-square method](https://en.wikipedia.org/wiki/Middle-square_method)

---

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