Example Code

Infinite Monkeys on Infinite Typewriters (with LabVIEW)

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview

This application was written to prove (partly, atleast) the infinite monkey theory.

 

Description

Firstly, a bit of mind-boggling background...

The infinite monkey theorem states that a single monkey hitting random keys on a typewriter, for an infinite amount of time, will eventually type the complete works of William Shakespeare (or any given text for that matter!!).

Although purely academic, this theory is used to illustrate the awesome power of infinity. The probability of a monkey exactly typing the complete works of Shakespeare is so tiny that the chance of it occurring during a period of time (even a thousand orders of magnitude longer than the age of the universe) is extremely low, but it's not actually zero. Therefore, given an infinite period of time, a monkey rewriting the complete works of Shakespeare is not just a possibility, it’s an inevitability!!

In this context the "monkey" is not an actual monkey (as 1. monkeys have finite lifetimes and 2. This would surely be animal cruelty), but a metaphor for an abstract device that produces a random sequence of letters and symbols forever.


Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Open the Infinite Monkeys.vi and enter a series of ascii characters into the “Text to Match” control.
  2. Run the VI.
  3. The iteration count displays the number of typed.

 

Additional Information or References

Front Panel

FP (example.jpg

 

VI Snippet

145.png

 


IMPORTANT: T
o begin with, I would suggest typing a maximum of 4 characters (you can try additional characters afterwards)

Then hit the run arrow (or hit ctrl + R, if you are lazy like me)

 

Wait a few seconds as our virtual monkey furiously types random letters on its virtual typewriter. Eventually, our friendly, little virtual monkey will have typed your exact sequence of ascii characters.

 

Extra Feature: if you place a tick in the “Show Info” checkbox, then you will be greeted with an info-box on the completion of the typed text. The pop-up with explain how long our tireless virtual monkey would have taken to type your requested text, assuming he typed at a speed of one character per second.

 

InfoPopUp (2).jpg

 

As a truer test, I requested the monkey to type “to be or not to be”. This is a relatively long sentence, so I had to leave the application running on my work station over the weekend (please don’t tell our IT team). As you will see in the following screen capture, it took a very, very long time!

 

Effectively it took 15,241 years for the monkey to type just 6 words from a single Shakespeare play. There are a combined total of 884,429 words in Shakesperes 43 plays. 
Wow! Infinity is both Big and Clever!!

 

As a final technical point, it appears that I have committed a cardinal sin - placing front panel objects over an image. This is NOT the case! On the front panel, I have split the image into sections, and the front panel objects are placed directly on to the pane (...which I have painted brown).

 

Please note: no monkeys were harmed in the development of this application!

 

**This document has been updated to meet the current required format for the NI Code Exchange.**   

Rich Roberts
Senior Marketing Engineer, National Instruments
Connect on LinkedIn: https://www.linkedin.com/in/richard-roberts-4176a27b/

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Pete.Dunc
Active Participant
Active Participant
on

Nice concept, UI... and SubVI icons!


Regards,

Peter D