Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A Python interface to the ANU Quantum Random Numbers Server

Project Description

This project provides tools for interacting with The ANU Quantum Random Number Generator ( It communicates with their JSON API and provides a qrandom command-line tool, a Python API, and a Linux /dev/qrandom character device.

quantumrandom works on Python 2 and 3.


As of version 1.7, quantumrandom now uses SSL/TLS by default.


pip install quantumrandom

Command-line tool

$ qrandom --int --min 5 --max 15
$ qrandom --binary
$ qrandom --hex
$ qrandom --binary | dd of=data
^C1752+0 records in
1752+0 records out
897024 bytes (897 kB) copied, 77.7588 s, 11.5 kB/s

Creating /dev/qrandom

quantumrandom comes equipped with a multi-threaded character device in userspace. When read from, this device fires up a bunch of threads to fetch data. Not only can you utilize this as a rng, but you can also feed this data back into your system’s entropy pool.

In order to build it’s dependencies, you’ll need the following packages installed: svn gcc-c++ fuse-devel gccxml libattr-devel. On Fedora 17 and newer, you’ll also need the kernel-modules-extra package installed for the cuse module.


The /dev/qrandom character device currently only supports Python2

pip install ctypeslib hg+
sudo modprobe cuse
sudo chmod 666 /dev/cuse
sudo chmod 666 /dev/qrandom

By default it will use 3 threads, which can be changed by passing ‘-t #’ into the qrandom-dev.

Testing the randomness for FIPS 140-2 compliance

$ cat /dev/qrandom | rngtest --blockcount=1000
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=17.696; avg=386.711; max=4882812.500)Kibits/s
rngtest: FIPS tests speed: (min=10.949; avg=94.538; max=161.640)Mibits/s
rngtest: Program run time: 50708319 microseconds

Adding entropy to the Linux random number generator

sudo rngd --rng-device=/dev/qrandom --random-device=/dev/random --timeout=5 --foreground

Monitoring your available entropy levels

watch -n 1 cat /proc/sys/kernel/random/entropy_avail

Python API

The quantumrandom Python module contains a low-level get_data function, which is modelled after the ANU Quantum Random Number Generator’s JSON API. It returns variable-length lists of either uint16 or hex16 data.

>>> quantumrandom.get_data()
>>> quantumrandom.get_data(data_type='uint16', array_length=5)
[42796, 32457, 9242, 11316, 21078]
>>> quantumrandom.get_data(data_type='hex16', array_length=5, block_size=2)
['f1d5', '0eb3', '1119', '7cfd', '64ce']

Valid data_type values are uint16 and hex16, and the array_length and block_size cannot be larger than 1024. If for some reason the API call is not successful, or the incorrect amount of data is returned from the server, this function will raise an exception.

Based on this get_data function, quantumrandom also provides a bunch of higher-level helper functions that make easy to perform a variety of tasks.

>>> quantumrandom.randint(0, 20)
>>> quantumrandom.hex()[:10]
>>> quantumrandom.binary()[0]
>>> len(quantumrandom.binary())
>>> quantumrandom.uint16()
numpy.array([24094, 13944, 22109, 22908, 34878, 33797, 47221, 21485, 37930, ...], dtype=numpy.uint16)
>>> quantumrandom.uint16().data[:10]

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(7.6 kB) Copy SHA256 Hash SHA256
Source None Mar 17, 2013

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate