Quantum Random Number Generator Squirts Out Numbers Via MQTT

Sometimes you need random numbers — and properly random ones, at that. [Sean Boyce] whipped up a rig that serves up just that, tasty random bytes delivered fresh over MQTT.

[Sean] tells us he’s been “designing various quantum TRNGs for nearly 15 years as part of an elaborate practical joke” without further explanation. We won’t query as to why, and just examine the project itself. The main source of randomness — entropy, if you will — is a pair of transistors hooked up to create a bunch of avalanche noise that is apparently truly random, much like the zener diode method.

In any case, the noise from the transistors is then passed through a bunch of hex inverters and other supporting parts to shape the noise into a nicely random square wave. This is sampled by an ATtiny261A acting as a Von Neumann extractor, which converts the wave into individual bits of lovely random entropy. These are read by a Pi Pico W, which then assembles random bytes and pushes them out over MQTT.

Did that sound like a lot? If you’re not in the habit of building random number generators, it probably did. Nevertheless, we’ve heard from [Sean] on this topic before. Feel free to share your theories on the best random number generator designs below, or send your best builds straight to the tipsline. Randomly, of course!

15 thoughts on “Quantum Random Number Generator Squirts Out Numbers Via MQTT

      1. Schrodinger did his experiment in 1935. In the ’80-ies the average lifespan of a pet cat was 7 years, but recently it’s been stretched to over 13 years. https://en.wikipedia.org/wiki/Cat#Lifespan_and_health

        So even if we assume that Schrodinger used a kitten just starting on it’s first lifespan back then, it still would have needed an average of 10 years for each of it’s lifespans to still be alive.

        Radio active materials also have a strong tendency to shorten the lifespan of living beings.
        So Schrodinger’s cat is very likely dead by now.

        (I do make the assumption the cat was not pregnant)

  1. I’m sure I could make a worse version without a smartiepants Von Neumann extractor in ASM. Just record the audio of the noise with an i2s audio ADC, the digital bitstream is then read and hashed in a cryptographic hash function.

    1. Sure, but the Von Neumann extractor described in the github sounds really straight-forward. I think it’s just something like this:
      1. When an “event” happens, note the time T0.
      2. When another “event” happens, note the time Ta and calculate elapsed time since the last event, t1 = Ta – T0.
      3. When another “event” happens, note the time Tb and calculate elapsed time since the last event, t2 = Tb – Ta.
      4. If t1 > t2, output 0. If t1 < t2, output 1. If t1 = t2, do nothing.
      5. Set t1 = t2, Ta = Tb, and go to step 3.

      I didn’t dig into what an “event” is, but it could just Vin crossing zero.

    2. If you want to take that kind of approach, a fun method is to take a webcam, cover the camera with something very opaque, and turn the gain all the way up. This gives you a lot of entropy which you can use to seed whatever pseudorandom function you want. You can obtain very high bandwidth this way!

      Another way to eliminate the separate Von Neumann extractor is to use the PIO in the RP2040 to implement one there instead. This would offer very good performance at lower parts count — you could even use a faster entropy source. I implemented it separately mostly because not all my use cases require the RP2040, but I generally want the AVR (I have a lot of them in stock).

    1. Looking at the schematic, it’s a reverse-biased NPN emitter-base junction connected between the collector and emitter of a second NPN.

      The reverse-biased junction is basically a Zener diode with a breakdown voltage somewhere around 6.5V.

      Each pulse of current that goes through the junction turns on the second NPN. Given the connections, the second NPN shorts the emitter-base junction of the first, pulling its voltage below the breakdown voltage.

      That means no more current can go to the second NPN, so it turns off, letting the voltage across the reverse-biased junction go high enough to break down again. There will be a short delay as charge drains out of the second NPN’s base-emitter junction, and the length of that delay will depend on the amount of charge that came through the reverse-biased junction in the last breakdown.

      The result is a set of strong voltage spikes with separation between them. And since diode breakdown happens randomly, both in timing and amount of charge, the pattern will be pretty darned unpredictable.

    2. This generator here is really not very good. The problem is that reverse biased transistor junctions may (and will) degrade over time. The amount of degradation depends on multiple factors, like type of transistor but especially on junction current. My experience and measurement shows, that if designed correctly, it can last for years of 24/7 operation with slow signal level degradation, but if designed incorrectly, they are just not good.
      So 2 problems here:
      1) The junction current is way too high
      2) There is no way to monitor if the signal is correct

      The good way to do it would be to set the current lower, amplify the signal so it correctly fits the range of ADC on the MCU, and sample the signal (and do the extraction of bits in software). This way you can see the actual (average) amplitude of the signal and detect if the reverse junction is working correctly.

      Here is a good resource on the topic:
      http://holdenc.altervista.org/avalanche/index.html

      Also for example this project https://altusmetrum.org/ChaosKey/ got it wrong as well. I have 2 of these and they both generate noise not by quantum effect on the reversed junction, but by amplifying thermal noise and badly filtered power supply. The current is as well too high, so the transistors gets destroyed quickly and the amplification is way too high so even with the broken transistors, it just picks up some random noise from everywhere.

      1. I was concerned about that as well. So I ran one for about a year, expecting problems. Surprisingly, I could not find any!

        That being said, I can’t think of any good reason not to reduce the junction current.

  2. TRNG is actually much more complicated than it sounds. The difficulty is that if you make a mistake, in design or construction, it will still appear to “work” even though it is no longer secure.

    Its kind of like tying a knot your life will depend on. It’s theoretically “easy” yet in practice it is difficult because of the care you must exercise in doing it.

Leave a Reply to ziggurat29Cancel 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.