58,149,737,003,040,059,690,390,169 to one. Those are the odds against a monkey, hammering 18 random keys, typing the phrase "to be or not to be" — about to one. The idea that a monkey typing at random would eventually produce the complete works of Shakespeare goes back to the mathematician Émile Borel in 1913 [1], and it is quoted so often that it deserves a proper check. Everything we need is one rule of probability: the probabilities of independent events multiply.
The odds on six words
We must first state our model. Our monkey types on a simplified 27-key typewriter: the 26 letters plus a space bar — no capitals, no punctuation. Every keystroke is equally likely (probability per key) and independent of every other keystroke.
Independence is what makes the arithmetic easy. If two events are independent, the probability that both happen is the product of their probabilities. The chance the first keystroke is "t" is ; the chance the second is "o" is also ; the chance of "t" then "o" is .
The phrase "to be or not to be" contains characters, spaces included. The probability of typing it in given keystrokes is therefore:
A failed attempt tells the monkey nothing — it just keeps typing — and on average it will need about keystrokes before the phrase first appears. At a steady one keystroke per second:
That is roughly 130 million times the age of the universe — a figure of billion years that we derive in another article — for six words. Not the play. Not the soliloquy. Six words.
Every atom a monkey
Perhaps our monkey just needs colleagues. Let us hire the most absurd workforce imaginable: one monkey for every atom in the observable universe — about of them — each typing one key per second since the Big Bang, seconds ago. The total output is:
How long a specific passage could this cosmic typing pool be expected to produce? We need , and solving gives characters. Sixty-eight characters — not even the second line of the soliloquy.
Now compare that to the actual assignment:
-
One page of Hamlet is roughly characters, and . Our universe of monkeys falls short by nearly orders of magnitude.
-
The whole play contains roughly letters. Ignoring spaces entirely (a 26-key model, to be generous), the odds against typing it in one go are to one — a number whose digit count is itself a six-figure number.
Infinity does all the work
So how long would a monkey take to type Hamlet? On any physical timescale: forever. The infinite monkey theorem is mathematically true — with genuinely infinite time, the probability of typing Hamlet really does approach — but the word "infinite" is doing all of the work, because the required time dwarfs the age of the universe by hundreds of thousands of orders of magnitude. There has even been an experimental test: in 2003, researchers at the University of Plymouth left a computer keyboard with six Sulawesi crested macaques at Paignton Zoo for a month. The monkeys produced five pages consisting mostly of the letter S, then used the keyboard as a toilet [2]. Real monkeys, it turns out, are not even random.
References:
[1] Émile Borel, "Mécanique statistique et irréversibilité", Journal de Physique Théorique et Appliquée, 5e série, tome 3 (1913).
[2] Notes Towards the Complete Works of Shakespeare — the Vivaria Project, University of Plymouth / Paignton Zoo (2003).
Note: Our model assumes uniformly random, independent keystrokes on a 27-key typewriter. Real monkeys type nothing like randomly — which, as the Paignton Zoo experiment showed, only makes matters worse.