Sunday, August 16, 2009

Ininite Monkey Source

The Infinite Monkey Theorem states that given an endless source of random letters (such as, say, a monkey tirelessly hitting keys on a typewriter), eventually all kinds of useful things will be found within the garbage, purely by chance. All of human literature, surprising solutions to world problems, interesting medical, philosophical, and mathematical ideas are all possible, just absurdly unlikely. This of course can be compensated with more data sources (more monkey and more typewriters) and more time.
Mathematicians determined that this would work because while the chance of producing anything useful out of a random pile of letters is minuscule, it is not nonexistent. One gets a barn-megaparsec effect, which I'm naming after the totally insane unit of measurement. A barn is a ridiculously tiny measurement of area, used to measure the area of atomic collisions, and a megaparsec is an absurdly long measure of linear distance, thousands of light-years long. Multiplied together to form a measurement of volume, you get 2/3rds of a teaspoon. Practical for human use, but measured in the most ludicrous form possible. Same here, a tiny thing is multiplied by a huge thing to produce a moderate result.
The network working group even put out an April-Fools document describing how to do this on a computer: the infinite monkey protocol suite. Well, I can't put together an archiver, a literacy-recognizer, or an idea critic, but I can get you the monkey. In the C language, as I like it. Computer science readers, feel free to translate it into your own language.

#define CONTROLCHAR 32
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char monkeytype()
char output; // The output character chosen by the monkey
srand(time(0)); // Randomize timer
srand(rand()); // Rerandomize. Definitely a random character now.
ouput=CONTROLCHAR + rand() % ASCIIMAX; // Produce an output character.
while(output > 126) // If it's "Delete this letter" or an other unprintable....
ouput=CONTROLCHAR + rand() % ASCIIMAX; // Reroll. Unprintable is not allowed.
return output; // When satisfied, return the letter to the main program.
int main()
char letter; // Expect a "letter."
while(input!=ctrl+c) // Okay, I forget how to really say "Until the user hits ctrl+c."
letter=monkeytype(); // Type a "letter."
printf(letter); // Print it out.
} // Repeat.
return 0; // All went well? Good.

Presumably the protocol maintainer would modify the main block to instead first connect to the storage-handler, then monkeytype at it, listening for signals asking it to stop.

No comments:

Related Posts Plugin for WordPress, Blogger...