Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lava Lamp Random Number Generator

Lava Lamp Random Number Generator

(extracted from the now defunct SGI project at http://lavarand.sgi.com/cgi-bin/how.cgi via the magical Internet Archive Wayback Machine)

Lava Lamps can be used as a source of randomness, which can be used to establish a random number generator. The output of the RNG can then be consumed by various computer applications.

Step 1: Establish a chaotic system

(Set up Lava Lite® lamps in a machine room.)

Lava Lite lamps are very good chaotic sources when operated under conditions recommended by the manufacturer. We use the Eleck-trickTM Lava Lite lamp model, in part because it works well in colder conditions found in machine rooms but more importantly, it comes in rad colors!

Step 2: Digitize the chaotic system

(Take digital images of the Lava Lite lamps.)

An O2cam TM digital camera is set up in front of six Lava Lite lamps. The digital camera takes a picture of the Lava Lite lamps every once in a while:

Digital cameras are "noisy" by nature. Taking two pictures of the same object will more likely than not produce two different images. Digital cameras add digital noise to the visual signal that they process.

Step 3: Cryptographically hash the digitization of the chaotic system

(Feed the digital output through a number munger.)

The digital output of the image is then munged by an algorithm, which compresses and scrambles it. Thus the 921,600-byte image is transmogrified into an 140-byte "seed."

The technogeek explanation:

We use NIST's Secure Hash Standard rev 1 (SHS-1, sometimes called the Secure Hash Algorithm or SHA-1) to cryptographically hash the digitized image of the chaotic system (Lava Lite lamps) produced in step 2.

Our implementation of SHS-1 allows for the production of an n-way hash. An n-way hash produces n hash values, each of which is a hash of a every nth octet. In this example we use a 7-way hash, each of which produces a 160 bit value from every 7th byte of the digitized image. By hashing every 7th byte we avoid hashing the same byte of each pixel.

The 7-way SHA-1 hash of the above digitized image yields the following 140-byte base 16 value:

1f51fcba8eeed05d8d4caf6b85229c660495f2295315243d3c79cd1a
a6469bf5c0bf058962ea52151ae20ed71538f3b717804bd071681a9d
911939a48f70fb1f9d8dd6f42b68d5a2d7bab3f97c4d60746e67320a
5bf894b09bc8a9473da65133e554d442c9746b74ab17498396e6abaf
0d29ed1689270f657c9551f68934557aa3cfee43a30663caad12966e

Step 4: Seed a pseudo-random number generator

(Feed the 140-byte value through another number munger.)

The 140-byte value gets fed through the Blum Blum Shub - one of the best available number generators, its quality endorsed by respectable mathematicians everywhere. Think of a roulette game as an analogy - the pseudo-random number generator is the roulette wheel, the seed is how long the roulette wheel spins before it begins to slow down. The slot the ball falls into at the end is the resulting random number. Voila! You have a random number! Here is a sample 128-byte random number (in base 16):

b078be0ef23a6a38f6885ec521644d9de4a399b4298414014dfd245bc39664a1
6105f71148104e6aee68e1a54903247efa2d6713fb850bf9f0159cf0ddf11150
82c81414fd7043d7855beb85a8b0df72d0e66886de452430e6b10e505ce45dbc
7b708f2d821fcc0613d26d965d9109aebcf76a421c60c5b6b8ac3ba1f69abdc8

NOTE: This random data is provided 'as is'. Obviously the random data generated by these demos is not secure since anyone can see this same data. See our standard disclaimer.

The technogeek explanation:

We use the Blum Blum Shub pseudo-random number generator, which takes the product of two prime numbers and generates a very long, cryptographically strong sequence of pseudo-random bits.

The Blum Blum Shub is based on the low order bits of quadratic residues of a product of two Blum primes. Blum primes are primes that are 3 mod 4. A quadratic residue is the square of a value modulo some value, in this case, modulo a product of two Blum primes. In this example we are using the following 1062-bit product of two Blum primes:

5360751114622011236087979022735306713592537659947455285353148181
8526455500785383194936281698585494806464721601253386562653528822
5543322562532917886396992291116815877218495559211688377961466145
0857446201926232198015028137924055146650866097197909406089918491
4133568666470293429076893274969016410915119621659901793350665953
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment