Generating Random Numbers With A Fish Tank

While working towards his Computing and Information Systems degree at the University of London, [Jason Fenech] submitted an interesting proposal for generating random numbers using nothing more exotic than an aquarium and a sufficiently high resolution camera. Not only does his BubbleRNG make a rather relaxing sound while in operation, but according to tools such as ENT, NIST-STS, and DieHard, appears to be a source of true randomness.

If you want to build your own BubbleRNG, all you need is a tank of water and some air pumps to generate the bubbles. A webcam looking down on the surface of the water captures the chaos that ensues when the columns of bubbles generated by each pump collide. In the video after the break [Jason] uses two pumps, but considering they’re cheaper than lava lamps, we’d probably chuck a few more into the mix. To be on the safe side, he mentions that the placement and number of pumps should be arbitrary and not repeated on subsequent installations.

To turn this tiny maelstrom into a source of random numbers, OpenCV is first used to identify the bubbles in the video stream that are between a user-supplied minimum and maximum radius. The software then captures the X and Y coordinates of each bubble, and the resulting values are shuffled around and XOR’d until a stream of random numbers comes out the other end. What you do with this cheap source of infinite improbability is, of course, up to you.

While this project has been floating around (no pun intended) the Internet for a few years now, it seems to have gone largely overlooked, and was only just brought to our attention thanks to a tip from one of our illustrious readers. An excellent reminder that if you see something interesting out there, we’d love to hear about it.

[Thanks to David for the tip.]

27 thoughts on “Generating Random Numbers With A Fish Tank

    1. I was wondering why one couldn’t shine a lamp through it to a larger area photocell, (Or use lens system so it samples a decent area through it) and source the noise from that. Or even audio sample from the fizz of the bubbles popping on surface.

      However, he’s meant to be studying it in detail, and doing a computing degree so had to make the problem a nail for his particular hammer.

  1. Actually it’s not that random; it’s just hard to calculate. Each bubble’s move has some impulse caused by the previous ones. If you can capture 2 subsequent frames of the tank in 3d, you can compute the vectorial representation of the all bubbles and It turns out to be just a complex physics question to calculate the next bubble’s move. Lol.

    1. I call physics!

      My guess is that the water is also moving (has momentum) and that you’d need to know a lot more about the invisible water flows than you might think. Two frames of just bubbles will _certainly_ not suffice. I have no clue how many you’d need. And there’s a good chance that the process ends up chaotic in the physics sense: infinitessimal differences in initial conditions make large changes in the overall.

      Still, I think that you’re right that it’s not random. It may be in principle work-outable.

      1. I think you mean it’s chaotic in the maths sense, which it almost certainly is, as due to the flows, it will share a number of properties with weather patterns, the classic chaos example.

        His nicely routed wires don’t look physically chaotic.

      2. Apparently a container of water isn’t “still” until it’s been sitting a couple of days. Therefore seemingly random motion is already imparted by the method of filling it.

        I would be more worried that there might be a 50 or 60Hz variation of bubble density that might come out with extensive analysis.

    2. As long you haven’t solved the [Navier–Stokes existence and smoothness problem] there is no way to tell whether is assembly creates true randomness.
      If you have, congrats to your $ 1M ;)

      You can calculate the dynamics of one bubble via the [Rayleigh–Plesset equation] if you make a plethora of assumptions (i.e. infinite body of water), but this is just a fish tank, so…
      Furthermore every pump creates a sh!t-ton of bubbles, so you have to take bubble-bubble interaction into consideration – and you have 3 pumps…
      So even if the resulting bubble-pattern isn’t truly random, good luck calculating it XD

    3. You’re definitly right.
      Every real random number is hard to calculate, by an agreed definition of ‘random’.
      ‘True’ random isn’t possible unless you’re able to compute the universe including yourself. That’s how deep the rabbithole of random goes.
      This guy actually achieves a relatively high approximation of random with cheap stuff.

  2. In the “Hitchiker’s Guide to the Galaxy”, the “Infinite Improbability Generator” used brownian motion from a really nice hot cup of tea as a source of randomness. Perhaps this should be considered for your next version.

    But then, what do I know? I never get invited to those parties… :/

  3. “What you do with this cheap source of infinite improbability is, of course, up to you”

    Obviously, you use some of the bits to select which of the n>2 pumps will be active for the next batch of random bits. Or maybe toggle servos to tweak the pump nozzle output directions.

    It’d be interesting if this could be miniaturized into a portable form factor. Maybe using colored water and clear mineral oil.

  4. The bubbles displace the water and changes the resistance. If you were to place the bubble stones between two electrodes and measure the resistance with a current source and ADC. This simplifies the measurement to something a cheap microcontroller can do.

    Use deionized water and limit the voltage across so that you are not performing an electrolysis.

  5. Since simpler RNGs are still random enough that we can’t quantify their randomness through observation….
    How can we tell if this more complicated version produces better results?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.