Random LED Dots: Entropy Library for Moah Speed with Less Gimcrackery

A discussion over the Squidwrench Operating Table about injecting entropy into VMs before / during their boot sequence reminded me that I wanted to try the Entropy library with my 8×8 RGB LED matrix:

8x8 RGB LED Matrix - board overview

8×8 RGB LED Matrix – board overview

The original version trundled along with random numbers produced by timing Geiger counter ticks. The second version, digitizing the amplified noise from a reverse-biased PN junction, ran much faster.

What’s new & different: the Entropy library measures the jitter between the ATmega328 watchdog timer’s RC oscillator and the ceramic resonator (on Pro Mini boards) driving the CPU. It cranks out four bytes of uncorrelated bits every half-second, which isn’t quite fast enough for a sparkly display, but re-seeding the Arduino PRNG whenever enough entropy arrives works well enough.

One could, of course, re-seed the PRNG with Geiger bits or junction noise to the same effect. The key advantage of the Entropy library: no external hardware required. The downside: no external hardware required, so, minus those techie transistors / resistors / op amps, it will look like Just Another Arduino Project.

Reverse-bias noise amplifier - detail

Reverse-bias noise amplifier – detail

Le sigh.

In any event, the Entropy library has excellent documentation and works perfectly.

The Arduino PRNG can produce results fast enough for wonderfully twinkly output that’s visually indistinguishable from the “true” random numbers from the Geiger counter or PN junction. I dialed it back to one update every 5 ms, because letting it free-run turned the display into an unattractive blur.

The top trace shows the update actually happens every 6 ms:

Entropy TRNG - LED update vs refresh

Entropy TRNG – LED update vs refresh

The lower trace shows that each matrix row refresh takes about a millisecond. Refreshes occur on every main loop iteration and interfere with the update, not that that makes any difference. Should it matter, subtract one from the update period and it’ll be all good.

The Arduino source code as a GitHub Gist:



  1. #1 by scruss on 2016-08-30 - 19:46

    The Entropy library is rather good, isn’t it? The documentation is great, and it makes all of its limitations clear.

    • #2 by Ed on 2016-08-30 - 21:27

      The knockoff Arduino Pro Minis I’m using probably have counterfeit ATmega328s that surely produce weird and non-random timing jitter, but … for my simple needs, that doesn’t matter!

  1. Switch Contact Bounce | The Smell of Molten Projects in the Morning