# Monkeys and Hamlet and Statistics

**URL:** <https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496>\
**Category:** Factual Questions\
**Created:** [July 13, 2000, 10:48pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496 "2000-07-13T22:48:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ren](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@ren](https://boards.straightdope.com/u/ren)\
**Post date:** [July 13, 2000, 10:48pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/1 "2000-07-13T22:48:58Z")

</div>

This was originally posted in [another thread](http://boards.straightdope.com/sdmb/showthread.php?threadid=30605). I’m copying it here because I have a question and didn’t wanna hijack that thread. (Mods, is that sort of think OK?)

So, Joe\_Cool said:

> [@](#):
>
> Sorry to hijack your hijack, but your eminded me of something I saw at The Brunching Shuttlecocks website (home of the C.Y.B.O.R.G. name generator):
> 
> > [@](#):
> >
> > The saying is as follows: if you take X monkeys, set them at typewriters, and have them type for some indefinite period of time, eventually they will compose Y, where X is a positive whole number – generally a large one – and Y is one or more of the works of Shakespeare, often Hamlet. That’s leaving aside the whole “infinite monkeys” thing. Obviously enough, an infinite number of monkeys will instantly come up with Hamlet, along with every other piece of literature from the past, present, and future.
> > 
> > No, no, let’s deal with the merely impossible: some definite number of monkeys pounding away like so many journalists in black-and-white 40’s crime movies, working towards the Holy Grail of simian stenography, the text of Hamlet. But why Shakespeare? Why Hamlet? There are a lot of things that monkeys chained to typewriters can accomplish, let us not forget. Here, then, is a list of things our theoretical monkeys are – mathematically speaking – likely to come up with long before they finish Hamlet.
> > 
> > [ul]  
> > [li]Several perfect cryptograms of Hamlet.[/li][li]A long Usenet argument over whether Boba Fett is alive, complete with spam-blocked e-mail addresses.[/li][li]The phrase “Jesus Christ my ass is chafed” repeated for the length of two letter-sized pages.[/li][li]The text of Hamlet, except everyone dies of food poisoning in Act II.[/li][li]A brief but accurate write-up of the most embarrassing thing you ever did, with full names, dates, and places.[/li][li]Hop on Pop[/li][li]The Denny’s Kids Menu.[/li][li]This article, including HTML mark-up.[/li][li]A short story entitled “Babysitter’s Passion.”[/li][li]“Iii#jd89 pp98&(\*(^9 879j; FF”[/li][li]The text of Hamlet, except that Horatio is named “Elvis.”[/li][/ul]

My question has to do with a claim like the last bullet, or the first: Given that the lengths of the texts are identical, it seems to me that each is equally likely. How can it be **more likely** to come up with the “Elvis” version, or a perfect cryptogram?

---

<div class="post-metadata">

**Author:** ![BurnMeUp](https://avatars.discourse-cdn.com/v4/letter/b/91b2a8/32.png) [@BurnMeUp](https://boards.straightdope.com/u/BurnMeUp)\
**Post date:** [July 13, 2000, 10:58pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/2 "2000-07-13T22:58:37Z")

</div>

This reminds me of a Simpsons episode where Mr Burns is showing Homer his house, in in one room he has a bunch of monkeys chained to typewriters and he says “Here I have monkeys working wound the clock to eventually write the best liturature ever read” then he pulls a page from a monkey and reads it “It was the best of times, it was the morst of times… you stupid monkey!”

---

<div class="post-metadata">

**Author:** ![wolfman](https://avatars.discourse-cdn.com/v4/letter/w/a8b319/32.png) [@wolfman](https://boards.straightdope.com/u/wolfman)\
**Post date:** [July 13, 2000, 10:59pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/3 "2000-07-13T22:59:09Z")

</div>

Well the whole deal is just about the random chances of a consecutive series of keys will randomly end up being the same. However because Horatio is longer than Elvis, it has more total keystrokes and is less likely to occur.  
As for the cryptogram, i’m assuming they mean with one every letter transposed for a different one. There are so comnbinations of transposed letters, that there are a great number of perfect cryptogram versions of Hamlet. Since the length is the same, and any single cryptogram is as likely as the original version, there is a much greater chance of getting one of the perfect cryptgrams, then getting the original.

---

<div class="post-metadata">

**Author:** ![tcburnett](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tcburnett](https://boards.straightdope.com/u/tcburnett)\
**Post date:** [July 13, 2000, 11:18pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/4 "2000-07-13T23:18:03Z")

</div>

I agree with wolfman. But there is also the implied necessity of coming up with everything ever written that contains fewer words than ‘Hamlet’. So listing a few possibilities doesn’t cover the situation completely.

It is only when you have progressed through every combination of every written word in every text shorter than Hamlet that you can start working on Hamlet. All shorter possibilities will have been covered.

Then, when you get to Hamlet itself, all possible combinations of all written words must be used until you reach the correct text. Since there are a fixed number of words in Hamlet, the mathematical probability of determining how long it would take to obtain ‘X’ words in ‘y’ order should be possible. What say, sailor? Big number? Larger than a Gazillion but smaller than a Googolplex?

---

<div class="post-metadata">

**Author:** ![ren](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@ren](https://boards.straightdope.com/u/ren)\
**Post date:** [July 13, 2000, 11:26pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/5 "2000-07-13T23:26:14Z")

</div>

> [@](#):
>
> because Horatio is longer than Elvis

aha! I missed that point…

> [@](#):
>
> It is only when you have progressed through every combination of every written word in every text shorter than Hamlet that you can start working on Hamlet.

Huh?!?!? I don’t understand how you came up with that.

I can see that a shorter text may have a higher probability of occurring before a longer one, but that is not the same thing as saying that it _will_ occur. Theoretically, Hamlet could be the first thing that a single monkey types out.

---

<div class="post-metadata">

**Author:** ![CalMeacham](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/calmeacham/32/35_2.png) [@CalMeacham](https://boards.straightdope.com/u/CalMeacham)\
**Post date:** [July 13, 2000, 11:27pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/6 "2000-07-13T23:27:28Z")

</div>

Bob Newhart used to have a routine about that. The problem was that the monkeys kept coming up with “To be, or not to be, that is the gesornenplatz…”  
There’s a professor someplace who tried doing his kind of thing with random number generators. It got eally interesting when he had the probability of a letter coming up dictated not by random chance, but by the relative probability of that letter being used. It got really interesting when he started basing the probabilities on pairs of letters, or sets of three letters. By the time you got to fifth-order monkeys they were starting to produce stuff that looked like text. (For some reason, four letter monkys produced a lot of dirty words – no joke.)

But he decided that it was very unlikely that even higher-order monkeys would reproduce his original text (the one on which he based his letter counts) – there wasn’t enough “noise” in the program.

So if you do this with monkeys, make sure they’re bonded “white noise” monkeys.

---

<div class="post-metadata">

**Author:** ![tcburnett](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@tcburnett](https://boards.straightdope.com/u/tcburnett)\
**Post date:** [July 13, 2000, 11:43pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/7 "2000-07-13T23:43:17Z")

</div>

> [@](#):
>
> \*Originally posted by ren \*  
> \*\*
> 
> > [@](#):
> >
> > It is only when you have progressed through every combination of every written word in every text shorter than Hamlet that you can start working on Hamlet.
> 
> Huh?!?!? I don’t understand how you came up with that.
> 
> I can see that a shorter text may have a higher probability of occurring before a longer one, but that is not the same thing as saying that it _will_ occur. Theoretically, Hamlet could be the first thing that a single monkey types out. \*\*

Because it only after you have finished using every combination of every word in every text shorter than Hamlet that you know you have not completed Hamlet. Then you have to start over with one more word. Now that I think about it, the entire probability could be solved mathematically if you knew how many monkeys were chained up. But not by me. I developed dexterity so I could count on my fingers.

---

<div class="post-metadata">

**Author:** ![ren](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@ren](https://boards.straightdope.com/u/ren)\
**Post date:** [July 13, 2000, 11:48pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/8 "2000-07-13T23:48:32Z")

</div>

> [@](#):
>
> Because it only after you have finished using every combination of every word in every text shorter than Hamlet that you know you have not completed Hamlet.

Still not following this. Like I said, the first thing the monkey types could be Hamlet. Are you saying that’s not the case?

---

<div class="post-metadata">

**Author:** ![jayron\_32](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jayron\_32](https://boards.straightdope.com/u/jayron_32)\
**Post date:** [July 14, 2000, 12:24am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/9 "2000-07-14T00:24:59Z")

</div>

ok… look at it this way:

We’re not saying that the monkeys WILL create all texts shorter than hamlet, we are just saying that it is MUCH MORE PROBABLE for a monkey to randomly come up with a text shorter than Hamlet. How much more probable? Well, lets look at a VERY simplified version.

Lets say our monkeys only have a keyboard with letters, a space bar, and basic punctuation, like .,:;?! and that we are allowing the monkeys to not have to do capital letters (which adds a level of dextral complexity monkeys may not be capable of). The odds of hitting any single, 1 character is 1 in 33 (26 letters , space, and 6 punctuation marks). Now, the odds of hitting any specific 2 character combination is, like **to** 1 in 1089 (33 x 33). Now, to get to the phrase \*\* to be or not to be? \*\* by random character generation would be odds of 1 in 7.10 x 10[sup]28[/sup] (that’s 19 characters so 1 in 33[sup]19[/sup]). Now, to do the above phrase WITHOUT the questionmark is 33 times more likely, or 1 in 2.17 x 10[sup]27[/sup]. Thus, it is MAGNIFICENTLY more likely to reproduce say, Hop on Pop, than to reproduce Hamlet; and even changing Horatio’s name to Elvis makes the text 1089 times more likely to be generated for EVERY time horatio’s name appears. (this is an exponential not multiplicative effect, so if horatio’s name only appeared twice in the text, you’d have made it into a text 1,185,921 times more likely to occur.) Thus, the general rules of probability indicate texts signifcantly shorter than Hamlet will almost HAVE to come up more often than Hamlet itself would.

---

<div class="post-metadata">

**Author:** ![ren](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@ren](https://boards.straightdope.com/u/ren)\
**Post date:** [July 14, 2000, 12:42am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/10 "2000-07-14T00:42:17Z")

</div>

> [@](#):
>
> We’re not saying that the monkeys WILL create all texts shorter than hamlet,

Well, _your_ not saying it, and I agree with you.

> [@](#):
>
> only after you have finished using every combination of every word in every text shorter than Hamlet that you know you have not completed Hamlet.

This I don’t agree with. Why do texts have to be a certain size?

OK, I need to type a piece of Hamlet before I type all of Hamlet, because the piece is part of the whole. So one can deduce that a piece of Hamlet must appear before all of Hamlet appears. But the rest I just don’t follow. I have to complete _all_ texts shorter than Hamlet? I have to do that to know I _didn’t_ complete Hamlet?

---

<div class="post-metadata">

**Author:** ![ren](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@ren](https://boards.straightdope.com/u/ren)\
**Post date:** [July 14, 2000, 12:45am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/11 "2000-07-14T00:45:00Z")

</div>

Now that I think more about it, “bonded white noise monkeys” belongs in the [Band Names](http://boards.straightdope.com/sdmb/showthread.php?threadid=29048) thread…

---

<div class="post-metadata">

**Author:** ![Dystopos](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@Dystopos](https://boards.straightdope.com/u/Dystopos)\
**Post date:** [July 14, 2000, 1:35am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/12 "2000-07-14T01:35:02Z")

</div>

Of course, we’re neglecting how many monkeys chained to typewriters might ALREADY have typed Hamlet…which is undoubtedly more than those who have typed Hamlet with Elvis in the role of Horatio.

Modern monkeys prefer cut-and-paste, of course.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [July 14, 2000, 2:14am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/13 "2000-07-14T02:14:52Z")

</div>

Quoth CalMeacham:

> [@](#):
>
> There’s a professor someplace who tried doing his kind of thing with random number generators. It got eally interesting when he had the probability of a letter coming up dictated not by random chance, but by the relative probability of that letter being used. It got really interesting when he started basing the probabilities on pairs of letters, or sets of three letters. By the time you got to fifth-order monkeys they were starting to produce stuff that looked like text. (For some reason, four letter monkys produced a lot of dirty words – no joke.)

I believe that the term for such constructions is Markhov chains… One presumes, then, that the professor was named Markhov.

---

<div class="post-metadata">

**Author:** ![Grendel69](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Grendel69](https://boards.straightdope.com/u/Grendel69)\
**Post date:** [July 14, 2000, 2:15am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/14 "2000-07-14T02:15:37Z")

</div>

But in time these monkeys took to write these pieces, wouldn’t they evolve and eventually become Homo sapien. Upon which writing something like Hamlet would still be impressive, just not as much as if monkeys did it.

Ok ok ok. I am being a smartass.

---

<div class="post-metadata">

**Author:** ![Myrr21](https://avatars.discourse-cdn.com/v4/letter/m/e495f1/32.png) [@Myrr21](https://boards.straightdope.com/u/Myrr21)\
**Post date:** [July 14, 2000, 2:18am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/15 "2000-07-14T02:18:27Z")

</div>

IOf any of you are familiar with the collection of One Acts “All in the Timing”, it contains a One Act (obviously) on the topic (with 3 monkeys, incidentally). It does teach us something about monkeys typing Hamlet: bribe them with cigarettes, they’ll work much faster.

---

<div class="post-metadata">

**Author:** ![bibliophage](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bibliophage/32/7615_2.png) [@bibliophage](https://boards.straightdope.com/u/bibliophage)\
**Post date:** [July 14, 2000, 4:24am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/16 "2000-07-14T04:24:56Z")

</div>

If you’re interested in the history of the idea, see [this site](http://www.research.att.com/~reeds/monkeys.html) which traces its evolution. [ul]Borel had illiterate men typing away in 1913  
Eddington had monkeys typing a Shakespeare sonnet, among other things, in 1930  
Douglas Adams in 1979 had monkeys typing _Hamlet_  
[/ul]

That link also has

> [@](#):
>
> It seems likely that Borel came up with the whole thing, but lots of people think T. H. Huxley did. Research continues. Borel used it a lot from 1913 on, and at some point on shifted from the `les plues riches bibliotheques du monde'' to the Bibliotheque Nationale. (Borel proved the `normal number theorem’’ in 1909, according to which `almost all' numbers between 0 and 1 exhibit all patterns of digits in their decimal expansions; random choice of such a number is equivalent to dactylographic monkeys typing digits at random, etc, etc.) According to Ed Schwalenberg, there is a paper `Monkey Business: From Borel’s ‘Singes dactylographes’ to Asimov’s ‘The Monkey’s Finger’ ‘’ , by Prof. David Bell, chairman of the Romance Studies department at Duke University.

Apparently, the whole thing was not invented, as I had vaguely recalled, by Borges in his story “The Library of Babel”. The story is similar, though.

---

<div class="post-metadata">

**Author:** ![CalMeacham](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/calmeacham/32/35_2.png) [@CalMeacham](https://boards.straightdope.com/u/CalMeacham)\
**Post date:** [July 14, 2000, 4:26am UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/17 "2000-07-14T04:26:12Z")

</div>

Chronos:

No, it wasn’t Markov. I’d remember his name from statistics.

I have the article in an old (circa 20 years ago) issue of American Scientist, but I can’t remember where I put t.

---

<div class="post-metadata">

**Author:** ![Robot\_Arm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/robot_arm/32/18280_2.png) [@Robot\_Arm](https://boards.straightdope.com/u/Robot_Arm)\
**Post date:** [July 14, 2000, 3:05pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/18 "2000-07-14T15:05:31Z")

</div>

> [@](#):
>
> \*Originally posted by CalMeacham \*  
> **Bob Newhart used to have a routine about that. The problem was that the monkeys kept coming up with "To be, or not to be, that is the gesornenplatz…"**

I’ve heard the Bob Newhart routine. He was talking mostly about how this experiment would also require a staff of people to read everything the monkeys wrote, and what an utterly sucky job that would be. Except he didn’t use the words “utterly sucky”.

> [@](#):
>
> **There’s a professor someplace who tried doing his kind of thing with random number generators. It got eally interesting when he had the probability of a letter coming up dictated not by random chance, but by the relative probability of that letter being used. It got really interesting when he started basing the probabilities on pairs of letters, or sets of three letters…**

The Jargon File (aka _The Hacker’s Dictionary_) refers to this as Dissociated Press. Description and examples at: [http://www.tuxedo.org/~esr/jargon/html/entry/Dissociated-Press.html](http://www.tuxedo.org/~esr/jargon/html/entry/Dissociated-Press.html)

---

<div class="post-metadata">

**Author:** ![MinkMan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minkman/32/19170_2.png) [@MinkMan](https://boards.straightdope.com/u/MinkMan)\
**Post date:** [July 14, 2000, 5:16pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/19 "2000-07-14T17:16:48Z")

</div>

For those who are interested, there was a recent internet protocol about this problem published as RFC 2795. You can read it here: [http://www.faqs.org/rfcs/rfc2795.html](http://www.faqs.org/rfcs/rfc2795.html)

---

<div class="post-metadata">

**Author:** ![ZenBeam](https://avatars.discourse-cdn.com/v4/letter/z/3ab097/32.png) [@ZenBeam](https://boards.straightdope.com/u/ZenBeam)\
**Post date:** [July 14, 2000, 5:56pm UTC](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496/20 "2000-07-14T17:56:09Z")

</div>

The question of how long of a text you end up with isn’t specified. Do the monkeys randomly select a size each time they start typing? If so, with what probability distribution with respect to length? is “End of text” just one more character the monkey might type? Does the monkey just type an endless stream of text, and you can start reading anywhere?

[Next page](https://boards.straightdope.com/t/monkeys-and-hamlet-and-statistics/25496.md?page=2)
