Skip to main content

Quantum random numbers

Project description

Quantum random numbers in Python

Tests

This package brings the ANU quantum random numbers to Python 3.6+.

The default pseudo-random generator in Python is replaced by calls to the ANU API that serves real quantum random numbers.

pip install quantum-random

Just import qrandom and use it like you'd use the standard Python random module. For example,

>>> import qrandom

>>> qrandom.random()
0.15357449726583722

>>> qrandom.sample(range(10), 2)
[6, 4]

>>> qrandom.gauss(0.0, 1.0)
-0.8370871276247828

The qrandom module exposes a class (qrandom.QuantumRandom) derived from random.Random with a random method that outputs quantum floats in the range [0.0, 1) (converted from 64-bit ints). Overriding random.Random.random is sufficient to make the qrandom module behave like the random module as described in the Python docs. A batch of 1024 quantum numbers are fetched from the API at a time. If you wish to pre-fetch, use qrandom.fill(n), where n is the number of 1024-batches.

To run the tests locally, you will need poetry and Python 3.6-3.9.

poetry install
poetry run tox

See here for a visualisation and a Kolmogorov–Smirnov test.

Project details


Download files

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

Source Distribution

quantum-random-0.2.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

quantum_random-0.2.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page