true-qrandom
True quantum random number generation using IBM Quantum hardware via Qiskit Runtime.
Classical computers produce pseudo-random numbers — deterministic sequences that only appear random. true-qrandom uses real quantum hardware: a qubit placed in superposition is measured, producing a result that is fundamentally unpredictable by the laws of quantum mechanics.
Features
- 🔬 True quantum randomness — powered by IBM Quantum hardware
- 🔌 Familiar
randommodule API — same interface, quantum backend - 🧪 Local simulator mode — develop and test with no credentials
- ⚡ Single multi-qubit circuit per request — efficient and fast
- 🔢 Multiple output types — integers, floats, bytes, and raw bits
More features planned for v0.2.0.
Installation
pip install true-qrandom
Requires Python >= 3.10.
Setup
You need two things from IBM — both are free:
| What | Where to get it |
|---|---|
| IBM Cloud API key | cloud.ibm.com/iam/apikeys |
| Instance CRN | quantum.cloud.ibm.com → Create instance → copy the CRN |
Set them as environment variables:
IBMQ_API_KEY=your_ibm_cloud_api_key
IBMQ_INSTANCE=your_ibm_instance_crn
Usage
from true_qrandom import QuantumRandom
# Reads IBMQ_API_KEY and IBMQ_INSTANCE from environment
qr = QuantumRandom()
qr.randint(1, 100) # → e.g. 42
qr.random() # → e.g. 0.7341...
qr.randbytes(4) # → e.g. b'\x3f\xa1\x09\xcc'
qr.choice(["a", "b", "c"]) # → e.g. "b"
You can also pass credentials explicitly:
qr = QuantumRandom(
api_key="your_ibm_cloud_api_key",
instance="your_ibm_instance_crn"
)
Simulator mode (no credentials needed)
qr = QuantumRandom(use_simulator=True)
qr.random()
Simulator mode uses AerSimulator — not true quantum randomness. Use IBM hardware for production.
API Reference
QuantumRandom(api_key=None, instance=None, use_simulator=False)
| Parameter | Type | Description |
|---|---|---|
api_key |
str |
IBM Cloud API key. Falls back to IBMQ_API_KEY env var. |
instance |
str |
IBM instance CRN. Falls back to IBMQ_INSTANCE env var. |
use_simulator |
bool |
Use local AerSimulator instead of IBM hardware. |
Methods
| Method | Returns | Description |
|---|---|---|
random() |
float |
Random float in [0.0, 1.0) |
randint(a, b) |
int |
Random integer N such that a <= N <= b |
randbytes(n) |
bytes |
n random bytes |
choice(seq) |
any |
Random element from a non-empty sequence |
Low-level access
from true_qrandom import generate_bits
bits = generate_bits(num_bits=16, use_simulator=True)
print(bits) # → "1011001001110100"
print(int(bits, 2)) # → 45172
How It Works
|0⟩ ──[ H ]───────────────[ M ]──► 0 or 1 (bit 1)
|0⟩ ──[ H ]───────────────[ M ]──► 0 or 1 (bit 2)
: :
: :
|0⟩ ──[ H ]───────────────[ M ]──► 0 or 1 (bit N)
│
▼
transpile to native gates 1 0 1 1 0 ... → int / float / bytes
- Each qubit starts in ground state
|0⟩ - A Hadamard gate (H) puts it into 50/50 superposition
(|0⟩ + |1⟩) / √2 - The circuit is transpiled to the native gate set of the target chip
- Measuring collapses the qubit to
0or1— governed by quantum mechanics, not an algorithm - N bits are assembled into the requested output type
Development
git clone https://github.com/yourname/true-qrandom
cd true-qrandom
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
# Simulator tests — no credentials needed
pytest
# Hardware tests
IBMQ_API_KEY="..." IBMQ_INSTANCE="..." pytest -k real_hardware
Requirements
- Python >= 3.10
qiskit >= 1.0qiskit-ibm-runtime >= 0.41qiskit-aer >= 0.14(simulator mode)
License
MIT — see LICENSE
Contributing
Contributions are welcome! Open an issue or pull request on GitHub.
Metadata
Release files for true-qrandom 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| true_qrandom-0.1.0.tar.gz | 5.7 kB | Without provenance | Details for true_qrandom-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| true_qrandom-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for true_qrandom-0.1.0-py3-none-any.whl |
Total release size: 12.0 kB
Release files / true_qrandom-0.1.0.tar.gz
| Download URL | true_qrandom-0.1.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66bbddfefd88efc19af2cfe0ded9c0013ca461af8e537f6561fa46ffd6cb5083
|
|
BLAKE2b-256 checksum How to use checksums |
04d164aa741bbc7422b506d527f4abe5d08240a1871eae42cb9027792add8313
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / true_qrandom-0.1.0-py3-none-any.whl
| Download URL | true_qrandom-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8502c77e7ffcd1e8887a4cfddfd25061d7fa9c0882af8ed9c02149fa7654792e
|
|
BLAKE2b-256 checksum How to use checksums |
fc40d3924249b40c468d545642f2e10d91a51679f97988250b861ea6bbad5636
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for true-qrandom 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.