TOPICS
Search

Infinite Monkey Theorem


The infinite monkey theorem states that a monkey pressing typewriter keys independently at random for an infinite amount of time will almost surely type any prescribed finite string of characters, and will in fact type it infinitely many times (Tassion 2025). More precisely, let X_1,X_2,... be independent and identically distributed random variables taking values in a finite alphabet A containing at least two symbols, with P(X_n=a)=p_a>0 for every a in A. For a fixed string w=w_1...w_m, the probability that one prescribed block of m symbols equals w is

 q=product_(j=1)^mp_(w_j)>0.

The events that w occurs in successive disjoint blocks of length m are independent, so the probability that it occurs in none of the first N such blocks is (1-q)^N, and

 lim_(N->infty)(1-q)^N=0.

Equivalently, the second Borel-Cantelli lemma shows that w occurs infinitely often almost surely. Since the collection of finite strings over a finite alphabet is countable, with probability one every such string occurs infinitely often.

The statement concerns probability one, not logical certainty. For example, the possible infinite output consisting of a single symbol repeated forever contains most strings zero times, but that output has probability zero. The theorem is related to normal numbers, but is weaker: a normal number has the correct limiting frequency for every finite digit block, whereas mere occurrence of every finite block imposes no such frequencies. The typing-monkey metaphor goes back at least to Borel (1913).


See also

Almost Surely, Borel-Cantelli Lemma, Independent and Identically Distributed, Normal Number, String

Explore with Wolfram|Alpha

References

Borel, E. "Mécanique Statistique et Irréversibilité." J. Phys. Théor. Appl. 3, 189-196, 1913. https://doi.org/10.1051/jphystap:019130030018900.Tassion, V. "The Infinite Monkey Theorem." §3.4 in Probability Theory. Zürich, Switzerland: ETH Zürich, pp. 41-42, 2025. https://metaphor.ethz.ch/x/2025/hs/401-3601-00L/mainappendix.pdf.

Cite this as:

Weisstein, Eric W. "Infinite Monkey Theorem." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/InfiniteMonkeyTheorem.html

Subject classifications