Production-grade guide to quantum random number generation covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Quantum Random Number Generation
Quantum random number generation harnesses quantum mechanical phenomena—such as photon detection events, vacuum phase fluctuations, or tunneling currents—to produce bit sequences that are, by definition, unpredictable by any classical algorithm. If your work requires cryptographic‑grade unpredictability, simulation seed independence, or scientific sampling without statistical leakage, a true random source is mandatory; pseudo‑random number generators (PRNGs) fail these checks because their output is deterministic given the same seed. This page covers the engineering pathways to obtain, integrate, and troubleshoot quantum random numbers without vendor‑specific mechanics locked into the exposition.
Many cloud quantum‑random‑number services expose a REST endpoint that returns a JSON payload containing a bit string of the requested length. The typical client flow is: obtain an authentication token from the provider’s console, send a POST or GET with the desired bit length, and parse the returned data. Most providers use a bearer token issued after account registration; the exact header name and token acquisition flow differ, but the HTTP pattern is consistent.
Example: fetching 256 bits from a public ANU QRNG instance
curl -sS "https://qrng.anu.edu.au/API/json?length=256" \
-H "Accept: application/json"
The command uses only real flags (-sS for silent but show errors, -H for custom headers). The query parameters (length, type) are documented by the service; other providers may use different parameter names or a POST body instead of query strings, but the overall structure—curl with an Accept or Authorization header, a JSON‑compatible request, and a JSON response—remains the same.
Parsing the output
curl -sS "https://qrng.anu.edu.au/API/json?length=256" | jq -r '.data[]'
jq is a standard tool; -r strips the surrounding quotes so the raw byte values are printed. If the service returns an array under a different key, adjust the filter accordingly. A 401 Unauthorized response means the token is missing or expired; a 429 Too Many Requests indicates rate‑limiting, which some public instances enforce per IP or per API key.
Typical error text you may encounter
curl: (7) Failed to connect to ... — network unreachable or DNS failure.curl: (52) Empty reply from server — the endpoint returned no body; verify the URL and query parameters.jq: error: null input at ... — the API returned an empty or malformed JSON; check the service status or your request parameters.When you need a continuous source of quantum‑derived randomness for seeding operating‑system cryptographic pools, hardware QRNG devices present a character device under Linux. The rng-tools package reads from that device and mixes the entropy into the kernel’s CSPRNG.
Loading a USB or PCIe QRNG device
sudo rngd -r /dev/hwrng -o /dev/urandom
-r /dev/hwrng tells rngd to read from the hardware random‑number device. On many systems this appears as /dev/hwrng; if the device uses a different path (e.g., /dev/cuaU0), adjust accordingly.-o /dev/urandom directs the output to the kernel’s urandom pool, which applications then read via getrandom() or /dev/urandom.If the device is not present or not readable, rngd emits a diagnostic:
rngd: error while reading from /dev/hwrng: Input/output error
Typical causes: the device is not plugged in, lacks firmware, or the current user does not have read permission (remedy with sudo or chmod 666 /dev/hwrng).
Software fallback when no hardware is attached
haveged -w 1024
haveged uses processor cycle timing jitter to generate entropy. It is not quantum, but it serves as a stop‑gap when hardware QRNG is unavailable. Start it as a system service (systemctl start haveged) or run it in the background.
Sharp edges
rngd versions offer a -l flag to log the estimated entropy rate; inspect those logs after extended uptime.dd if=/dev/urandom bs=1M count=1000) may outpace the device’s true‑random output rate, causing rngd to block or log entropy pool overflow. Monitor /proc/sys/kernel/random/entropy_avail.rngd without sudo on a device owned by root yields Permission denied. Create a udev rule or add your user to a hwrandom group if your distribution provides one.Qiskit provides a programmable interface to IBM Quantum backends. The same circuit‑execution pattern used for algorithm prototyping also yields measurement outcomes that, on a real quantum processor, are influenced by quantum noise—making them suitable for QRNG prototyping. The code below is standard Qiskit; it does not reference any IBM‑specific config keys or UI elements.
from qiskit import QuantumCircuit, execute, Aer
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
# Execute on a simulator that records shot counts (replace with a hardware backend for true QRNG)
job = execute(qc, Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()
counts = result.get_counts(qc)
# Extract the most frequent outcome as a random bit string
bit_string = max(counts, key=counts.get)
print(f"Generated bit string (simulated): {bit_string}")
QuantumCircuit(1, 1) creates one qubit and one classical bit.qc.h(0) puts the qubit into an equal‑superposition state.shots=1024 requests 1024 measurement samples; the resulting counts dict maps bit strings to frequencies.Aer.get_backend('qasm_simulator') with an IBM Quantum backend that records raw shot data (e.g., a ibm_quantum device accessed via Qiskit Runtime). The API contract—execute, result(), get_counts()—remains identical; only the backend name changes.Common failure modes in this pattern
QiskitBackendNotFoundError: Backend 'ibm_quantum_...' does not exist or is unavailable — verify your account quota and the backend’s operational status via the IBM Quantum dashboard.QiskitBackendApiError: The backend does not support the circuit — some simulators or devices reject certain gate sets; simplify the circuit (remove conditional operations, etc.) if this appears.counts dict — usually means shots was set to zero or the job was submitted without a valid backend. Ensure shots ≥ 1.| Symptom | Likely cause | Quick check |
|---|---|---|
curl returns 403 Forbidden to the QRNG API | Missing or expired bearer token | Renew the token from the provider’s console; ensure the Authorization header format matches the spec (typically Bearer <token>). |
rngd logs entropy drain and urandom stalls | Device entropy rate < consumer demand | Reduce read frequency, or add a second QRNG device; monitor /proc/sys/kernel/random/entropy_avail. |
| Qiskit job times out after the default 5‑minute limit | Backend queue depth or shot count too high | Request a higher timeout via the runtime service, or reduce shots to the minimum needed for statistical sufficiency. |
| Bit‑string distribution shows repeated patterns even on hardware | Calibration drift or mis‑configured readout | Run a quick tomography job; if the bias persists, recalibrate the backend or switch to a different device. |
| JSON payload from the API has an unexpected shape | API version mismatch | Check the service’s documentation for the current version; adjust query parameters or Accept headers accordingly. |
When any of these occur, the failure is usually silent in the sense that the program does not crash—it simply produces weak or biased randomness, which may go undetected until cryptographic tests (e.g., dieharder, statistical test suite) flag the output.
This page was rewritten on 13 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy