random number generator

Update to Arduino Random Library!!!

Recently I have been working on the new api for the Arduino Random library. The library now has methods that return different integer sizes from byte to long. I’m not sure if I’ll add long long though as the delay would be too great. This is because the library will block the MCU until it has gathered all of the entropy. If the source of randomness going into the Arduino’s ADC is not very random the library can take a long time to generate the bits. This is especially true of the von neumann debiasing code since it truncates long stretches of ones or zeros.

The library is based on code by Rob Seward albeit heavily modified. Most of the debiasing code remains the same as well as the calibration code. The new code is now up on Github at https://github.com/infomaniac50/Random/. Feel free to fork away and make changes as you see fit. If you use the code please include links back to this blog. I’m sure Rob would like to see some attribution to him as well.

If anybody has any questions feel free to leave a comment, but please, only if you are human.

Posted by admin in Electronics, Programming, 0 comments

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

Posted by admin in Electronics, Programming, 4 comments