A New Electronic Die: Open Source, Hardware Generated Random Numbers.

            “Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.” – John Von Neumann, 1951

Here is the finished device, turned on and displaying the number 4.

I’ve blogged previously about the development process for my latest project, an artificial die designed for die-based Role Playing Games. When I started this project, I had several design goals in mind: I wanted it to be extremely small and easy to carry, yet have 6 buttons to “roll” each of the standard sizes of die (D4, D6, D8, D10, D12, and D20). I also wanted it to based on a Random Number Generator (RNG) implemented in hardware instead of using the built in pseudo-random number generator. As those who have been watching the Show And Tell will know, I’m proud to say that I’ve succeeded. If you’d like to see it in action, a short demo video is available here..

My first step was to learn as much as I could about the Random Generation process, so I could design my own generator. As described previously, I found an open source design that I was able to implement. In this design, the Zener Effect of a 1.22V Zener Diode is used to generate Avalanche noise, which is then amplified through a 2n3904 NPN transistor and a pair of high-speed Op Amps, then delivered to the Microprocessor as a digital input. The microprocessor implements a debiasing algorithm known as the Von Neumann corrector to take the input noise distribution, which could have an uneven balance of 0s and 1s, and turn it into an even distribution of 0s and 1s. When the conditions of the corrector are met, the new random bit is mixed into a 32 bit number. Since this is implemented within a timer interrupt that triggers every 32 microseconds, the random number is updated extremely quickly. If you want to learn more about the RNG support circuitry or the software, check out the source files for this project. The Hardware process is described on the Schematic, and the software process is documented within the source code.

This is the rear side of the Electronic Die, with all of the circuitry shown.

To check that this device worked properly, I sampled the D20 option 250 times, and performed a Pearson’s Chi-Squared test based on the null hypothesis that the source data is uniformly distributed. Suffice it to say, it passed, and I could not reject the null hypothesis. I also borrowed the method of testing from the original designer of the RNG hardware, so if you’d like to look at the precise statistical methods, feel free to check them out here.

This is the output Frequency Histogram for 250 rolls of the electronic 20-sided die.

Because I wanted the device to be easy to use, I selected a two-digit seven-segment display, and found small tactile momentary switches to use for the UI. Since I wanted this project to be as small as possible, I decided to use Surface Mount devices for the RNG components and microprocessor and put them beneath the seven-segment display, on the underside of the board. I selected the Atmega8 to keep the LED driving simple (it has enough pins to drive both digits simultaneously, to keep the input switches on as few pins as possible (I’m using a resistor ladder, and an ADC to read the result), and to have a small package to fit within the .6” spaced rows of pins on the seven-segment display. Because I was able to place all of the components (besides the switches and display) on the underside of the board, the top of the device is clean and simple and the PCB is kept to 1.1” x 1.25”, small enough to easily attach it to a 2xAA battery pack. Since the batteries would run out in under 10 days due to the high (~10mA) quiescent current use of the ADC and RNG circuitry, a simple power switch is included to turn power to the whole device on and off. At one-off prices, all of the components can be bought for about $10. The PCB is small, so if you buy from Laen over at DorkbotPDX (Who, by the way, awesomely accepted several last-minute design file changes, on a weekend no less) it’s about $7 for 3 boards.

In short, this is a simple, easy to use artificial die. When a button is pressed, the machine generates a random number in the appropriate range, displays it on the screen for several seconds, and then turns off the display. If you use this device, you don’t have to worry about carrying around a bag of dice, finding an even rolling surface, or losing a die. And in the process, I learned about Hardware RNGs, and designed my first mostly surface-mount PCB. And again, thank you to Leon Maurer for laying a lot of the groundwork for the design of the RNG. This project is released under the CC BY/SA License, and the design files are available at my github page.


Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat and our Discord!

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Join over 38,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — New Products 11/15/2024 Featuring Adafruit bq25185 USB / DC / Solar Charger with 3.3V Buck Board! (Video)

Python for Microcontrollers – Adafruit Daily — Python on Microcontrollers Newsletter: A New Arduino MicroPython Package Manager, How-Tos and Much More! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

EYE on NPI – Adafruit Daily — EYE on NPI Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

Adafruit IoT Monthly — The 2024 Recap Issue!

Maker Business – Adafruit Daily — Apple to build another chip at TSMC Arizona

Electronics – Adafruit Daily — SMT Tip – Stop moving around!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !


1 Comment

  1. Nice explanation of the RNG theory (and practice)!

Sorry, the comment form is closed at this time.