Infinite monkey theorem: can a monkey type Shakespeare?
Give a monkey a typewriter and infinite time, and it will type Shakespeare. That's the theory: every key is random, so any text turns up sooner or later. Watch a monkey hit the keys and the paper fill with gibberish, with every stretch that matches your text lit up. To type the word bananas, 7 letters on 30 keys, the odds are 1 in 22 billion, and a chimp typing a key every second its whole life has only about a 5 % chance. Scientists ran the numbers for every chimp on Earth, 200,000 of them, typing until the universe ends: a line of Hamlet, yes; Shakespeare's complete works, almost certainly never. The universe dies first.
How it works
- Press Play: the monkey hits random keys and the paper fills up; the letters that match the start of your text light up yellow, in the row of tiles too, and a whole find turns green.
- Read the tiles: the odds of the text at one place, the expected wait, the chance in the time allowed and the keys typed so far. Bananas on 30 keys: 1 in 22 billion, about a 5 % chance in a chimp's life.
- Follow the chart: each curve is the chance of one more letter of the text against time, from a second to the end of the universe, and every extra letter pushes the curve 30 times further.
- Type your own text, try more monkeys (every chimp on Earth, one for every person), more time, another keyboard or the zoo's monkeys, or press Step to type until the text gets one letter further.
The theory
The infinite monkey theorem says that a monkey hitting keys at random on a typewriter for an infinite amount of time will almost surely type any given text, such as the complete works of William Shakespeare.
The reason is simple: every key is random, so every sequence of keys has some chance, however small, of coming up next, and with infinite tries every chance comes true. The French mathematician Émile Borel used typing monkeys in 1913 to describe things that are possible but so unlikely that they never happen, and the astronomer Arthur Eddington put it in 1928 as an army of monkeys strumming on typewriters that might write all the books in the British Museum.
Why bananas takes a lifetime
A keyboard with 30 keys (the letters, a space, a full stop, a comma and an apostrophe) gives the monkey 30 choices for every key. To type bananas, it has to hit b, then a, then n, then a, then n, then a, then s:
\[30\times 30\times 30\times 30\times 30\times 30\times 30=30^{7}\,,\]
about 21.9 billion possibilities, and only one is right.
At a key a second, that is about 694 years of typing on average. A chimp lives about 35 years, a little over a billion keystrokes, so its chance of typing bananas in its whole life is about 5 %. Every extra letter makes the odds 30 times longer.
Every chimp on Earth, until the universe ends
In 2024 the mathematicians Stephen Woodcock and Jay Falletta put the theorem to a finite test: the 200,000 or so chimpanzees alive today, each typing a key a second, until the heat death of the universe, about \(10^{100}\) years from now.
That is about \(6\times 10^{112}\) keystrokes, a number with 113 digits. It is enough to type any given text of up to about 76 characters, such as a line of Hamlet, many times over. But Shakespeare's complete works have some 5 million characters, and their odds are 1 in 10 to the power of more than 7 million. The universe dies long before the monkeys get there.
When a zoo really tried it
In 2003 researchers from the University of Plymouth left a computer keyboard in the enclosure of six crested macaques at Paignton Zoo in England for a month. The monkeys produced five pages of text, mostly the letter S, with a few A, J, L and M, and they also bashed the keyboard with a stone and used it as a toilet.
Real monkeys are not random typists: they have favourite keys, and a typist that hits one key far more often than the others makes most texts even less likely. Choose the zoo's monkeys as the typist to see it.
Using the app
Give a monkey a typewriter and infinite time, and it will type Shakespeare. That's the theory: every key is random, so sooner or later any text turns up. Press Play and watch the monkey hit the keys. The paper fills with gibberish, and every time the letters on it match the start of the text, they light up in yellow, in the row of tiles above too; a whole find turns green.
The tiles put numbers on "sooner or later". To type the word bananas, 7 letters on 30 keys, the odds are \(30^{7}\), 1 in 22 billion. A chimp typing a key every second for its whole life, about 35 years, has only about a 5 % chance.
So scientists ran the numbers for every chimp on Earth, 200,000 of them, typing until the universe ends, in \(10^{100}\) years. A line of Hamlet: yes, many times over. The first lines of a sonnet: almost certainly not.
Shakespeare's complete works, some 5 million characters: never. The universe dies first. The chart shows why: each curve is the chance of one more letter of the text against time, from a second to the end of the universe, and every extra letter pushes the curve 30 times further.
Type your own text, pick a keyboard, more monkeys or more time, or the zoo's monkeys: when a zoo really tried it, in 2003, the monkeys mostly typed the letter S. Step types until the text gets one letter further, Speed goes from a key a second to a million.
Save image, record a video with the clatter of the keys, or open the picture in the photo editor with the pencil, where the monkey, the typewriter, the paper, the text and every curve are layers of their own.
Frequently asked questions
What is the infinite monkey theorem?
It says that a monkey hitting keys at random on a typewriter for an infinite amount of time will almost surely type any given text, even the complete works of Shakespeare. Every sequence of keys has a chance, however small, and with infinitely many tries every chance comes true.
It is a way of picturing probability and infinity, not a claim about real monkeys.
What are the odds of a monkey typing bananas?
On a keyboard of 30 keys, each of the 7 letters has a 1 in 30 chance, so the odds of bananas at any one place are 1 in \(30^{7}=21{,}870{,}000{,}000\), about 1 in 22 billion. A monkey typing a key a second needs about 694 years on average, and a chimp typing every second of its 35-year life has about a 5 % chance.
Could all the chimps on Earth type Shakespeare before the universe ends?
No. Woodcock and Falletta (2024) worked it out for the 200,000 or so chimpanzees alive today, each typing a key a second until the heat death of the universe in about \(10^{100}\) years: about \(6\times 10^{112}\) keystrokes.
That is enough for any text of up to about 76 characters, but Shakespeare's complete works, some 5 million characters, have odds of 1 in 10 to the power of more than 7 million.
Did anyone really give monkeys a keyboard?
Yes. In 2003 six crested macaques at Paignton Zoo in England had a computer keyboard for a month. They typed five pages, mostly the letter S, and also bashed the keyboard with a stone. Real monkeys are not random: they prefer some keys, which makes most texts even less likely.
Why does the wait for a word like aaa differ from the odds?
Because a word that overlaps itself makes its finds come in clumps. The expected number of keystrokes before a text first appears is the sum of \(1/P\)(prefix) over every beginning of the text that is also an ending of it.
For bananas only the whole word counts, so the wait is exactly \(30^{7}\) keys; for aaa on 26 keys it is \(26+26^{2}+26^{3}=18{,}278\) keys instead of 17,576.
Can I use the picture?
Yes. Save gives a PNG at the size you choose, Save JSON writes the odds, the wait and the chance with the letters typed, Record films the monkey typing with the clatter of the keys, and the pencil opens the picture in the PictorX photo editor with the monkey, the typewriter, the paper, the typed text, the tiles and every curve on layers of their own. In the editor itself it is under Apps ▸ Science ▸ Mathematics ▸ Infinite Monkey Theorem. Everything runs in your browser.
Infinite Monkey Theorem: how do I record a video?
Press the red Record button in the playback bar: it films what the stage shows. Press it again to stop, and the video is saved to your device. Recording is free; you only need to sign in. Without a subscription the video carries a small PictorX logo in a corner. The button beside Record opens the video options: the shape (as shown, square, story 9:16 or wide 16:9), the length (until you stop, or 5, 10, 15 or 30 seconds for social media) and the file: MP4, WebM or an animated GIF. For the sound, choose the app's own sounds or one of three music tracks: calm, bright or beat.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Go to Editor