April 4, 2020

213 words 1 min read

Raspberry Pi Hardware Random Number Generator

Raspberry Pi Hardware Random Number Generator

The Raspberry Pi has long come with a hardware random number generator, it’s right here: /dev/hwrng but the OS isn’t using it by default. You can test the quality of it’s output with the ent utility dd if=/dev/hwrng bs=1k count=1 |ent example output:

1+0 records in
1+0 records out
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.00956855 s, 107 kB/s
Entropy = 7.833804 bits per byte.

Optimum compression would reduce the size
of this 1024 byte file by 2 percent.

Chi square distribution for 1024 samples is 223.50, and randomly
would exceed this value 92.32 percent of the times.

Arithmetic mean value of data bytes is 125.6406 (127.5 = random).
Monte Carlo value for Pi is 3.200000000 (error 1.86 percent).
Serial correlation coefficient is -0.014492 (totally uncorrelated = 0.0).
To enable it OS wide you need to install rng-tools

sudo apt-get install rng-tools

and edit the following file /etc/default/rng-tools and uncomment the line below


Enable the service with sudo systemctl enable rng-tools and start/restart with

sudo systemctl restart rng-tools

This will now be stiring the pool (/dev/random) with the data from this device, thus making it available for the rest of the Operating System. You can check the available entropy before and after enabling rng-tools by looking in this file:

cat /proc/sys/kernel/random/entropy_avail