Skip to content

Instantly share code, notes, and snippets.

@rdev5
Forked from endolith/results.md
Created February 9, 2016 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdev5/0bb739ec2944f9e6505b to your computer and use it in GitHub Desktop.
Save rdev5/0bb739ec2944f9e6505b to your computer and use it in GitHub Desktop.
Randomness testing of Arduino TrueRandom

I ran

cat /dev/urandom >> devurandom.bin

which produced 31 MB of data in a few seconds. To get numbers from the Arduino, I ran:

stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
cat /dev/ttyUSB0 >> TrueRandom.bin

which took several days to produce 93 MB of data (rate of about 3.2 kbit/s)

ent test results for /dev/urandom:

~> ent devurandom.bin
Entropy = 7.999994 bits per byte.


Optimum compression would reduce the size
of this 30310400 byte file by 0 percent.

Chi square distribution for 30310400 samples is 242.19, and randomly
would exceed this value 50.00 percent of the times.

Arithmetic mean value of data bytes is 127.5034 (127.5 = random).
Monte Carlo value for Pi is 3.141565875 (error 0.00 percent).
Serial correlation coefficient is 0.000166 (totally uncorrelated = 0.0). 

Results for TrueRandom:

~> ent TrueRandom.bin
Entropy = 7.544390 bits per byte.


Optimum compression would reduce the size
of this 92810048 byte file by 5 percent.

Chi square distribution for 92810048 samples is 131287892.21, and randomly

would exceed this value 0.01 percent of the times.

Arithmetic mean value of data bytes is 93.7178 (127.5 = random).
Monte Carlo value for Pi is 3.682216212 (error 17.21 percent).
Serial correlation coefficient is -0.008583 (totally uncorrelated = 0.0).

Example dump of the data from TrueRandom:

~> od -t x1 /dev/ttyUSB0
0000000 10 30 e7 dd 89 5d 00 34 68 00 49 9a 99 b8 20 00
0000020 00 60 31 0b 70 00 00 f8 80 04 00 76 7b 46 33 fe
0000040 60 40 00 00 00 dd 47 68 70 c0 02 01 e1 02 0e fd
0000060 82 40 ce 64 5b d0 40 01 01 0d ef 34 1a 04 fe 80
0000100 19 80 00 01 6b fb 40 00 00 3c 00 04 64 1f 3e 01
0000120 80 41 bc 1a 87 63 84 4f 43 01 01 00 1c 32 5b 43
0000140 0d 8b a0 00 01 3a 0d 43 e0 00 02 00 01 40 4b 06
0000160 2b a0 00 08 0f 01 41 a6 09 ae 00 40 98 81 0f ab
0000200 e9 91 cf 00 40 48 20 fe 57 b5 b4 00 01 04 10 1a
0000220 2a c5 65 30 84 60 20 30 08 7e 12 04 06 a0 40 00
0000240 f0 41 67 ca 34 20 10 34 00 e0 51 1f e0 3c 00 10
0000260 9b 88 60 7d a0 23 41 00 00 06 03 5a bc 02 08 08
0000300 00 53 74 49 20 00 80 50 01 80 8c ca b0 00 02 64
0000320 00 00 2d 36 52 6f f0 00 00 00 bc 4d bf c3 00 80
0000340 68 0a 00 e5 23 04 02 00 56 11 02 00 38 3e 41 00
0000360 40 00 80 01 28 0b 6e 20 08 10 00 60 e5 4a c3 78
0000400 40 00 00 f0 33 f3 57 98 80 00 03 15 ea f9 40 68
0000420 00 8e 00 02 79 08 7f 00 78 08 01 04 72 77 60 03

So TrueRandom is not truly random. It tends to cluster around 0 and powers of 2:

Dot plot of sample from TrueRandom

#include <TrueRandom.h>
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.write(TrueRandom.randomByte());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment