Infinite Monkey Theorem
274,937 words loaded · 3 words · 1 in 20,782,585,149,174,950
Type your own words — leave a slot empty to search fewer words
Searching for 3 words
Each iteration picks 3 random words from the English dictionary and checks for a match. With 274,937 words, there are 20,782,585,149,174,950 possible combinations.
About Infinite Monkey Theorem
This tool provides a practical, browser-based demonstration of the Infinite monkey theorem[14], a concept rooted in probability theory[19]. By leveraging a pseudorandom number generator[20] (PRNG), the application simulates a monkey typing at a keyboard by generating a sequence of characters from a defined character set. Users can input a target phrase and observe the computational process as the system attempts to match the sequence through pure random chance. The simulation visualizes the immense timescale and computational effort required to produce even a short, specific string, offering a tangible perspective on concepts of probability, infinity, and combinatorial explosion[5].
The theorem states that a monkey hitting keys at random on a typewriter for an infinite amount of time will almost surely[1] type any given finite text, such as the complete works of William Shakespeare[24]. The term "almost surely" is a technical concept in measure theory, indicating that the probability of the event not happening is zero. The mathematical foundation for this assertion is often proven using the second Borel-Cantelli lemma[4], which deals with the probability of infinite sequences of events. While the thought experiment is a staple of popular science, its origins are deeply connected to formal mathematical and physical principles.
The concept was first articulated in the context of statistical mechanics[22] by French mathematician Émile Borel[9] in his 1913 article on the topic. It was later popularized by British astrophysicist Sir Arthur Eddington[2] in his 1928 book "The Nature of the Physical World". Eddington used the analogy to illustrate the timescale required for a collection of particles in a container to spontaneously return to a lower entropy state, a scenario statistically possible but practically impossible under the second law of thermodynamics[21]. This connects the abstract probability problem to fundamental principles governing the physical universe.
This digital simulation relies on a PRNG, which is an algorithm that produces a sequence of numbers that approximates the properties of random numbers. This is distinct from a hardware random number generator[12], which derives randomness from physical phenomena. The quality of a PRNG, such as the common Mersenne Twister[16] algorithm, is assessed by its statistical properties, which can be verified using test suites like the NIST Statistical Test Suite[27]. While the web standard for character encoding is UTF-8[23], this tool constrains the character set to a smaller subset of ASCII[3] to make the problem computationally approachable within a finite time.
The probability of generating a target string of length L from a character set of size C in a single attempt is 1 divided by C to the power of L. The expected number of trials to achieve success is C to the power of L. This exponential time[10] relationship illustrates why brute-force random search is infeasible for non-trivial problems. This aligns with principles like the no free lunch theorem[17] in optimization, which states that no single search algorithm is universally best for all problems. The monkey theorem, when simulated, becomes a stark demonstration of the inefficiency of undirected random search in a vast possibility space.
How to Use
- 1. Enter your desired target phrase in the designated input field.
- 2. Select the character set the simulation will use for random generation (e.g., lowercase letters, all printable ASCII).
- 3. Press the 'Start' button to initialize the random character generation process.
- 4. Monitor the real-time statistics, including elapsed time, total characters generated, and current generation rate.
- 5. The simulation will automatically halt and display a success message upon matching the target phrase.
- 6. To begin a new test, use the 'Reset' button to clear the current state and enter a new phrase.
Frequently Asked Questions
Is the random number generation used in this tool truly random?
No. This tool uses a pseudorandom number generator (PRNG), typically the one provided by the browser's JavaScript engine via `Math.random()`. PRNGs are deterministic algorithms that produce sequences that appear random but are fully determined by an initial seed. This is different from true randomness, which is sourced from unpredictable physical processes and requires a hardware random number generator[12].
What are the actual odds of this tool typing a work of Shakespeare?
The odds are infinitesimally small, making it a practical impossibility. For the phrase 'to be or not to be' (18 characters with spaces) using a 27-character set (a-z and space), the number of possible combinations is 27 to the power of 18. This is a number with 26 digits, far exceeding the estimated number of atoms in the observable universe. This illustrates the concept of large numbers[15] and orders of magnitude[18].
What specific PRNG algorithm does this simulation use?
The ECMAScript[28] specification, which standardizes JavaScript, does not mandate a specific algorithm for `Math.random()`. Browser implementations vary, but modern engines often use algorithms like xorshift[25] or its variants due to their speed and good statistical properties for non-cryptographic purposes. It is not a cryptographically-secure pseudorandom number generator[7].
How does this simulation relate to cryptography?
This simulation highlights why the PRNGs used for general purposes are unsuitable for cryptography[8]. The predictability of a standard PRNG would allow an attacker to guess keys, nonces, or other secret values. Cryptographic systems must use a cryptographically secure pseudorandom number generator (CSPRNG), which is designed to be unpredictable even if part of its internal state is known.
Why does it seem to get close to the phrase and then lose progress?
This perception is a result of cognitive biases like confirmation bias[6]. Each character generation is an independent and identically distributed[13] event. The system has no memory; it is not 'getting closer' or 'losing progress'. The probability of generating the next correct character is always the same, regardless of past results, a concept often misunderstood due to the gambler's fallacy[11].
What is the computational complexity of this problem?
The problem of finding a specific string of length L from a character set of size C via random generation has a probabilistic time complexity. The expected number of trials is C to the power of L. This is characteristic of an exponential time[10] algorithm, meaning the required time grows exponentially with the size of the input (the length of the string).
Could this tool be used to generate secure passwords?
Absolutely not. This tool demonstrates a brute-force search, which is what password crackers do. A secure password generator should create a random string using a CSPRNG, not attempt to randomly find a predefined one. For guidance on password policies, refer to authoritative sources like the NIST Special Publication 800-63B[26].
Sources (28)
- Wikipedia: Almost surely
- Wikipedia: Arthur Eddington
- Wikipedia: ASCII
- Wikipedia: Borel-Cantelli lemma
- Wikipedia: Combinatorial explosion
- Wikipedia: Confirmation bias
- Wikipedia: Cryptographically-secure pseudorandom number generator
- Wikipedia: Cryptography
- Wikipedia: Émile Borel
- Wikipedia: Exponential time
- Wikipedia: Gambler's fallacy
- Wikipedia: Hardware random number generator
- Wikipedia: Independent and identically distributed random variables
- Wikipedia: Infinite monkey theorem
- Wikipedia: Large numbers
- Wikipedia: Mersenne Twister
- Wikipedia: No free lunch in search and optimization
- Wikipedia: Orders of magnitude (numbers)
- Wikipedia: Probability theory
- Wikipedia: Pseudorandom number generator
- Wikipedia: Second law of thermodynamics
- Wikipedia: Statistical mechanics
- Wikipedia: UTF-8
- Wikipedia: William Shakespeare
- Wikipedia: Xorshift
- NIST: Digital Identity Guidelines (SP 800-63B)
- NIST: Statistical Test Suite for Random and Pseudorandom Number Generators
- TC39: ECMAScript Language Specification
About Matt George
I'm Matt George, a software engineer in the startup space. I run my own shop building software for early-stage founders, and I love making free tools and experiences that people actually use. Enjoy using Infinite Monkey Theorem!