December 6, 2017

How to Test Randomness (Entropy)

You can use ent http://www.fourmilab.ch/random/. On Ubuntu you can install via


$ sudo apt-get install ent

$ man ent
ent(1)                                                                                                              ent(1)

NAME
       ent - pseudorandom number sequence test

SYNOPSIS
       ent [options] [file]

DESCRIPTION
       ENT Logo

       ent performs a variety of tests on the stream of bytes in file (or standard input if no file is specified) and pro‐
       duces output on standard output; for example:

       Entropy = 7.980627 bits per character.

       Optimum compression would reduce the size
       of this 51768 character file by 0 percent.

       Chi square distribution for 51768 samples is 1542.26, and randomly
       would exceed this value 0.01 percent of the times.

       Arithmetic mean value of data bytes is 125.93 (127.5 = random).
       Monte Carlo value for Pi is 3.169834647 (error 0.90 percent).
       Serial correlation coefficient is 0.004249 (totally uncorrelated = 0.0).

       The values calculated are as follows:
...

And to test it


$ dd if=/dev/urandom bs=128 count=1 > 128bits

$ ent 128bits 
Entropy = 6.576057 bits per byte.

Optimum compression would reduce the size
of this 128 byte file by 17 percent.

Chi square distribution for 128 samples is 244.00, and randomly
would exceed this value 67.89 percent of the times.

Arithmetic mean value of data bytes is 132.7656 (127.5 = random).
Monte Carlo value for Pi is 3.238095238 (error 3.07 percent).
Serial correlation coefficient is 0.124230 (totally uncorrelated = 0.0).

No comments: