0

March 27, 2012 AT 9:20 am

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.


Check out all the Circuit Playground Episodes! Our new kid’s show and subscribe!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

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

Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground”Adafruit’s Apps!


Maker Business — How Authority and Decision-Making Differ Across Cultures

Wearables — Skin adherence

Electronics — LED Basics!

Biohacking — Stretchable EEG Temporary Tattoos

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.