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.7 to 3.10.

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

Install

pip install quantum-random

Usage

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

Under the hood, batches of quantum numbers are fetched from the API as needed and each batch contains 1024 numbers. If you wish to pre-fetch more, use qrandom.fill(n), where n is the number of batches.

Notes on implementation

The qrandom module exposes a class derived from random.Random with a random() method that outputs quantum floats in the range [0, 1) (converted from 64-bit ints). Overriding random.Random.random is sufficient to make the qrandom module behave mostly like the random module as described in the Python docs. The exceptions at the moment are getrandbits() and randbytes() that are not available in qrandom. Because getrandbits() is not available, randrange() cannot produce arbitrarily long sequences. Finally, the user is warned when seed() is called because there is no state. For the same reason, getstate() and setstate() are not implemented.

Tests

To run the tests locally, you will need poetry and Python 3.7-3.10. One way of having multiple Python versions is to use pyenv and list the versions in .python-version.

poetry install
poetry run tox

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

License

See LICENCE.

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-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

quantum_random-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file quantum-random-1.0.0.tar.gz.

File metadata

  • Download URL: quantum-random-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2

File hashes

Hashes for quantum-random-1.0.0.tar.gz
Algorithm Hash digest
SHA256 45134fd8a41a355e0600491b6ea8dd42f05c9d34060ba6ae0006b4c9b4eeb430
MD5 e68b78d1e32bb5eb2429069637aca894
BLAKE2b-256 13eea3bbd678fcee364dcb19f5c7065924f3f736dfe98a731864637f02fcd191

See more details on using hashes here.

File details

Details for the file quantum_random-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: quantum_random-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2

File hashes

Hashes for quantum_random-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 711d205c6e5e1dad69d7943bfe741e7c5f1176deac654e1689860b034fbe7278
MD5 185f6954248e768d4610297d1bb5eb7b
BLAKE2b-256 9152f1b37f81e464e7396efcd85f90fb1a0de5202ae4de931700baf5a4ce4663

See more details on using hashes here.

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