Skip to content

Instantly share code, notes, and snippets.

@TheMR-777
Created January 21, 2026 20:02
Show Gist options
  • Select an option

  • Save TheMR-777/21a8457b168f33aacae6762d01ed5683 to your computer and use it in GitHub Desktop.

Select an option

Save TheMR-777/21a8457b168f33aacae6762d01ed5683 to your computer and use it in GitHub Desktop.

1. The Mathematical Probability (The Idealized Scenario)

Let us assume, for the sake of calculation, that the monkey uses the pencil to write legible characters chosen completely at random, rather than drawing squiggles or eating the lead.

The Variables:

  • The Text: Shakespeare’s Hamlet contains approximately 130,000 characters (including letters, punctuation, and spaces).
  • The Character Set: To write English, you need at least 26 letters, a space, and basic punctuation. Let’s be generous and assume a "keyboard" of only 30 possibilities to simplify the math.

The Equation: The probability of getting the first character right is 1 in 30. The probability of getting the first two characters right is $1/30 \times 1/30$. The probability of getting the whole play right is $1/30^{130,000}$.

The Result: $$1 \text{ in } 30^{130,000} \approx 1 \text{ in } 10^{192,000}$$

What this number means: To understand how impossible this number is, consider the observable universe:

  • The number of atoms in the observable universe is roughly $10^{80}$.
  • The number of seconds since the Big Bang is roughly $10^{17}$.

The probability is not just "low." It is statistically indistinguishable from zero. If every atom in the universe were a monkey writing 1,000 characters per second since the beginning of time, they would not have even come close to producing the first page of Hamlet.

2. The Biological Probability (The Realistic Scenario)

You asked about an "average monkey" with a "pencil." This adds physical and behavioral variables that make the mathematical probability look optimistic.

The "Pencil" Variable: The mathematical model above assumes a typewriter, where pressing a key guarantees a legible letter. With a pencil, the monkey is not selecting from a finite set of 30 characters; it is selecting from an infinite set of geometric shapes. The probability of a monkey moving a pencil to accidentally form a perfect letter "T" is low; the probability of it forming a lowercase "e" is even lower.

The Behavioral Variable: In 2003, researchers at Plymouth University conducted a test closer to your question. They placed a computer keyboard in a cage with six Celebes crested macaques for a month.

  • The Result: The monkeys did not type random characters uniformly. They mostly bashed the keyboard with a stone. When they did type, they produced five pages consisting almost entirely of the letter 'S'. They also urinated and defecated on the keyboard.

The Final Answer

If you hand an average monkey a pencil and an empty book:

The probability is 0.

While mathematically, in an infinite timeframe with a random generator, it is theoretically non-zero (approx. $10^{-192,000}$), the physical constraints of the universe and the biological reality of the animal make it an absolute impossibility. The monkey will destroy the book or use the pencil as a tool/toy long before it writes a single coherent word, let alone a play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment