The Math Forum

Ask Dr. Math - Questions and Answers from our Archives
Associated Topics || Dr. Math Home || Search Dr. Math

Monkeys Typing Shakespeare: Infinity Theory

Date: 08/05/98 at 01:26:24
From: adam bridge
Subject: Infinity Theory

This request is for you to settle an argument within our household if 
you would be kind enough.

Many years ago I read somewhere that if you had an infinite number of  
monkeys sitting at an infinite number of typewriters for an infinite 
number of years typing at random then it could be accepted as a 
probability that one would eventually type the entire works of 
Shakespeare !

My wife and son say that that this view is incorrect; however, I would 
appreciate it if you can you shed any light on it from a mathematical 

Thanking you in anticipation

- Adam Bridge

Date: 08/13/98 at 13:35:41
From: Doctor Benway
Subject: Re: Infinity Theory

Hi Adam,

So you want the mathematical perspective on the "monkeys typing" 
scenario? Keep in mind that this is going to be an entirely 
theoretical answer. As you can imagine, there are some serious 
practical problems with having an actual infinite number of monkeys 
typing on an infinite number of typewriters (e.g. where would you put 
them? what would you feed them?), but since we're mathematicians we 
can gleefully ignore such considerations.

The cheap and easy answer to your question is, "yeah, they'll crank 
out Shakespeare's works... eventually." This is assuming they really 
are typing at  random. The monkeys with typewriters I have personally 
observed (mostly of the "young human/little sister" variety) tend to 
bang on the same keys repeatedly, so it's hard to imagine them 
actually turning out Shakespeare. But again, this is math so we will 
ignore the real world. 

As large as Shakespeare's collected works are, they are still finite.  
If you type at random, eventually some six-jillion-letter combination 
you type will end up being the collected works of Shakespeare. 

An easier way to think about this is picking lottery numbers. Imagine 
you are filthy rich and decide to buy a bunch of lottery tickets in an 
effort to win Powerball. Since you are filthy rich, you can afford to 
buy six jillion lottery tickets with every possible combination of 
numbers that could come up, and thus you would be guaranteed to win 
the lottery. It's the same concept with monkeys typing.

The grittiest detail in this problem is that the answer is only yes if 
we are talking about an infinite number of trials; that is, having an 
infinite number of monkeys or letting one monkey pound away for an 
infinite amount of time. If we are restricted to a finite number of 
monkeys and a finite amount of time, then the answer is no. It is 
entirely possible that in a finite amount of time a finite number of 
monkeys may type out nothing but pages upon pages of meaningless 
drivel. It's also possible (although unlikely) that one monkey may get 
it right the first time.  

A good way to think of this is to imagine rolling a six-sided die 
numerous times and waiting for a six to come up. It may come up on the 
first roll. It's possible that you could keep rolling and rolling 
millions of times without a six coming up, although you would expect 
it to come up within six rolls, since there is a 1/6 chance of a 6 
turning up on each roll.  

Let's do an actual example. Since the collected works of Shakespeare 
are a pretty lofty goal, let's just see about how long we would expect 
it to take for a monkey to crank out one of Shakespeare's sonnets, for 
example the following:

   Look in thy glass and tell the face thou viewest       -48
   Now is the time that face should form another          -45
   Whose fresh repair if now thou not renewest            -43
   Thou dost beguile the world unbless some mother        -47
   For where is she so fair whose uneard womb             -42
   Disdains the tillage of thy husbandry                  -37
   Or who is he so fond will be the tomb                  -37
   Of his self love to stop posterity                     -34
   Thou art thy mothers glass and she in thee             -42
   Calls back the lovely April of her prime               -40
   So thou through windows of thine age shall see         -46
   Despite of wrinkles this thy golden time               -40
   But if thou live rememberd not to be                   -36
   Die single and thine image dies with thee              -41

In the above sonnet I removed all punctuation, just leaving the 
letters and spacing--we can't expect too much; they're only monkeys, 
right?  If my letter count is correct, this leaves 572 letters and 
spaces. To further simplify, we won't worry about carriage returns, 
capital letters, or any other such stuff.  

Anyhow, say we give a monkey a special typewriter that has 27 keys 
(26 keys for the letters of the alphabet along with a space bar).  
We let the monkey type 572 characters at a time, pull the sheet out, 
and see if it's the sonnet. If not, we keep going. 

We'll do some calculations on the fly here to see how long this 
process will take. Got a calculator handy? First of all let's find out 
how many 572-letter possibilities there are for the monkey to type.  
We have 572 characters, and 27 choices for each character, so there 
will be 27^572 possibilities (that's 27 times itself 572 times).  
Punching this into my calculator... er... okay, on second thought 
better use a computer....I get the following number of possibilities:


It's a big number, about 5*10^818. 

Let's say our monkey can type about 120 characters per minute. Then 
the monkey will be cranking out one of these about every five minutes, 
12 every hour, 288 per day, and 105120 of them per year. Divide that 
big number by 105120 and you get that it would take that monkey about 
5*10^813 years to type out that sonnet.  

Now say we get 10^813 (that's ten followed by 813 zeros) monkeys 
working on the job. With that many monkeys working 24 hours a day, 
typing at random, one of them is likely to crank out the sonnet we are 
looking for within five years. If the monkeys are particularly 
unlucky, you may have to let them run an infinite amount of time 
before they crank out the desired sonnet, but chances are with this 
many monkeys on the job you will get results in five years.

To make a long story short, if you have only a finite number of 
outcomes and you take an infinite number of trials, you will end up 
getting the outcome you are looking for. 

Well, forget about making a long story short, I'll give you one more 
mind-blowing example. A typical digitized picture on your computer 
screen is 640 pixels long by 480 pixels wide, for a total of 
307200 pixels. Using only 256 different colors, you can get decent 
resolution. Now if you take 256^307200 (256 times itself 307200 times) 
you get... well, a pretty big number, but a finite number nonetheless.  
That's the number of different images you can have of that particular 
size. Any picture you would scan into a computer at that size and 
resolution will necessarily be one of those images. Therefore, 
contained in those images are the images of the faces of every human 
being who ever lived along with the images of the faces of every 
person yet to be born.  

Deep stuff, eh? I'll leave you with that thought. Thanks for writing.

- Doctor Benway, The Math Forum   
Associated Topics:
High School Permutations and Combinations
High School Probability
Middle School Probability

Search the Dr. Math Library:

Find items containing (put spaces between keywords):
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.