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
be independent and identically
distributed random variables taking values
in a finite alphabet
containing at least two symbols, with
for every
. For a fixed string
, the probability
that one prescribed block of
symbols equals
is
The events that
occurs in successive disjoint blocks of length
are independent, so
the probability that it occurs in none of the first
such blocks is
,
and
Equivalently, the second Borel-Cantelli lemma shows that
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).