Arduino Hardware Random Number Generator

I have been dabbling in cryptography for a while now and recently I got into random number generators. I found out that crypto libraries use random number generators all the time. You would have to be able to keep the output of the library unpredictable to ensure security. They do that mostly with pseudo random number generators. In other words they use an algorithm to generate the random numbers. These algorithms take a seed value to start the sequence and then only go for so long before the sequence repeats itself. So by using a true random number generator you can ensure that the output of the crypto library is kept secure.

I wanted a random number generator for my own use and I came upon a page on Rob Seward’s blog for a random number generator using the arduino as the hardware interface. The board works by taking the noise that you get from running the pn junction in reverse breakdown mode. Then amplifying it through two stages and sampling it with the Arduino’s ADC. I don’t have an oscilloscope so I don’t know what the noise distribution looks like. However, I have collected the random output on a computer and ran it through a basic entropy test. The output of ent.exe from http://www.fourmilab.ch/random/looks pretty good. This was done on a 5MB file so I imagine if I get more samples the chi squared distribution would increase as well.

C:\Apps>ent -b random.dat
Entropy = 1.000000 bits per bit.

Optimum compression would reduce the size
of this 41943040 bit file by 0 percent.

Chi square distribution for 41943040 samples is 0.00, and randomly
would exceed this value 95.89 percent of the times.

Arithmetic mean value of data bits is 0.5000 (0.5 = random).
Monte Carlo value for Pi is 3.141912514 (error 0.01 percent).
Serial correlation coefficient is 0.000081 (totally uncorrelated = 0.0).

Here are some pictures of the peripheral board I put the circuit on.

Here are some pictures of it connected to the Arduino.

Here is the code I used for the Arduino. I made quite a few modifications to it, most notably I transformed it into libraries so you can use it in your own code. The code should be up on GitHub shortly, but if not it means I am still tweaking it.

True Random Logger

4 comments

Marcus Wanner

Hey, just wanted to let you know that I built Rob’s circuit (http://robseward.com/misc/RNG2/) and hooked it up to a scope and saw some really beautiful stuff: http://i.imgur.com/O3VpA.jpg. I’ve also got a github tree full of code over at https://github.com/marcuswanner/randuino which might be interesting to you. Thanks for the write-up!

That looks great. What’s the bandwidth set to on the oscilloscope?

Marcus Wanner

Sorry, I meant to tell you. I think that’s .1 ms/cm (the solid lines) and .5 V/cm vertically, so that looks like 3-5 volts (just what the arduino wants). Keep in mind that the scope is from the 60s and probably hasn’t been calibrated in at least 50 years. It has a 4-digit serial number! :p

If you’d like to see a higher time resolution or something, just say the word.

I am very interested in using the Random Number Generator program. However, I am a newbie to Arduino programming. How can I use the Arduino IDE to attach your header files to the main program? I can’t seem to find descriptions on the net that actually work.

Leave a Reply