Skip to main content

Quantum random number generation using IBM Quantum (Qiskit)

Project description

Command Line Usage

You can use the package directly from the command line with the following commands:

# Show help and usage
python -m quantum_rng --help

# Generate a random bit
python -m quantum_rng --type bit

# Generate a string of 16 random bits
python -m quantum_rng --type bits --length 16

# Generate a random integer in [0, 1000)
python -m quantum_rng --type int --max 1000

# Generate a random float in [0, 1)
python -m quantum_rng --type float

# Generate a random string of length 12
python -m quantum_rng --type string --length 12

# Generate 8 random bytes
python -m quantum_rng --type bytes --length 8

# Generate a random boolean value
python -m quantum_rng --type bool

# Pick a random element from a sequence
python -m quantum_rng --type choice --seq A B C D

# Pick 2 unique random elements from a sequence
python -m quantum_rng --type sample --seq A B C D --k 2

# Generate a random UUID
python -m quantum_rng --type uuid

# Generate a 3x3 matrix of random floats
python -m quantum_rng --type matrix --rows 3 --cols 3

# Generate a random permutation of a sequence
python -m quantum_rng --type permutation --seq A B C D

# Generate a list of 10 random bits
python -m quantum_rng --type bit_array --length 10

# Generate a list of 10 random floats
python -m quantum_rng --type float_array --length 10

# Add --with-source to any command to show the randomness source
python -m quantum_rng --type int --max 1000 --with-source

quantum_rng

Quantum random number generation using IBM Quantum (Qiskit) and AerSimulator.

1. Environment Setup (Recommended)

Create and activate a clean Python environment:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

2. Install the Package

Install from PyPI:

pip install quantum_rng

3. (Optional) Set Up IBM Quantum Cloud Backend

Set your IBM Quantum API token as an environment variable:

Windows PowerShell:

$env:IBM_QUANTUM_TOKEN="your_token_here"

Windows Command Prompt:

set IBM_QUANTUM_TOKEN=your_token_here

If the token is set and the IBM provider is available, the package will use the IBM Quantum cloud backend. Otherwise, it defaults to AerSimulator (local quantum simulation).

4. Usage

Import and use the API functions:

from quantum_rng import get_random_bit, get_random_bits, get_random_int, get_random_float, get_random_string

# By default, functions return only the random value
print(get_random_bit())      # 0 or 1
print(get_random_bits(8))    # e.g. '01101001'
print(get_random_int(100))   # random int in [0, 100)
print(get_random_float())    # random float in [0, 1)
print(get_random_string(10)) # e.g. 'aB3kLmP9Qz'

# To get the randomness source as well, pass with_source=True
bit, source = get_random_bit(with_source=True)
print(bit, source)           # e.g. 1, 'quantum' or 'system'

5. CLI Usage

Generate a quantum random integer from the command line:

python -m quantum_rng

6. Fallback

If Qiskit or AerSimulator is unavailable, the package automatically falls back to system randomness.

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

qrngtools-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qrngtools-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file qrngtools-0.1.0.tar.gz.

File metadata

  • Download URL: qrngtools-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for qrngtools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 976505b9548d660c2fd8a3f083b1aa931ac451ecbecae5fbb568ec36526ee4df
MD5 75d3ce21176e434e567e4da316351baf
BLAKE2b-256 36832d05dcf2e159c32206bdb434b5b1eec242211b9a008875edb7e6bb39315a

See more details on using hashes here.

File details

Details for the file qrngtools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qrngtools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for qrngtools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d89bec01e22864d1ac8ca51ebad63d3e552759341e773debb6dfeca5673f11c
MD5 945532dd649b045b8318a39fb6600c67
BLAKE2b-256 f155f1ba87dab08100889f14fe9fdc884e04b0ac282eb2ff0d46bd7a8cb92e20

See more details on using hashes here.

Supported by

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