HUB
Sign inSign up
quantumrandom-lab logo

credkellar/quantumrandom-lab

By credkellar

β€’Updated 17 days ago

QuantumRandom-Lab: QRNG lab - Born-rule sampling, entropy, von Neumann extractor, test battery. Sim!

Image
Machine learning & AI
Developer tools
Data science
1

198

credkellar/quantumrandom-lab repository overview

⁠QuantumRandom-Lab πŸŽ²βš›οΈ

Quantum Randomness (QRNG) Lab β€” by Darion Kellar

Educational quantum randomness lab in ONE pure-Python file: a small statevector simulator (≀ 6 qubits, pure-Python complex amplitudes) whose Born probabilities are computed, not assumed β€” Hadamards give a provably uniform distribution, a qubit rotated by ΞΈ β‰  Ο€/4 is a provably biased source with P(1) = sinΒ²ΞΈ β€” plus Shannon and min-entropy accounting per bit and per byte, a von Neumann extractor that removes bias at the theoretical yield p(1βˆ’p), a simplified NIST-style test battery (labelled simplified), and a from-scratch kNN source classifier whose labels are generated by the battery itself.

Pure Python standard library. Zero dependencies. Zero network. Honest scope: this lab is a simulation β€” its sampling is driven by a seeded classical PRNG (seed printed in every report) so the demo is deterministic, which means its output is NOT true quantum randomness. Real QRNG randomness is unseeded and unreproducible. The classical PRNG contrast stream passes the battery and is labelled NOT quantum in the same report: passing statistics never certifies quantumness. Every certified-QRNG / real-key / gambling / beacon claim is a permanent HOLD gate (14 total).

⁠🐳 Quick start

docker pull credkellar/quantumrandom-lab:latest
docker run --rm credkellar/quantumrandom-lab:latest

The default command runs the full demo plus the built-in self-checks (CHECKS 54/54).

Run a specific command instead:

docker run --rm credkellar/quantumrandom-lab:latest python3 main.py checks   # CHECKS 54/54
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py sample   # Born-distribution sampling (seeded)
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py entropy  # Shannon + min-entropy per source
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py extract  # von Neumann yield: measured vs theory
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py tests    # simplified battery, all four streams
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py classify # kNN source classifier report
docker run --rm credkellar/quantumrandom-lab:latest python3 main.py holds    # 14 HOLD gates

β πŸ”¬ What's inside

  • Statevector simulator β€” ≀ 6 qubits, gates applied index-by-index; Hadamards on 3 qubits give 8 basis states at exactly p = 0.1250, asserted to 1e-12, then sampled to show counts follow the physics.
  • Biased source model β€” one qubit as cos ΞΈ|0⟩ + sin ΞΈ|1⟩: ΞΈ = Ο€/4 β†’ P(1) = 0.5000 (fair), ΞΈ = Ο€/6 β†’ P(1) = 0.2500 exactly, with the bias read off the simulated state.
  • Entropy accounting β€” fair stream: Shannon 1.0000/bit, 7.918/byte. The biased bit keeps 0.8113 bits of Shannon entropy but only 0.4150 bits of min-entropy β€” the cautious number, printed side by side.
  • Von Neumann extractor β€” 01 β†’ 0, 10 β†’ 1, pairs 00/11 discarded: 65,536 biased bits in, 12,105 out; measured yield 0.1847 bits/input bit vs theoretical p(1βˆ’p) = 0.1875; extracted P(1) = 0.5014.
  • Simplified battery (labelled) β€” monobit frequency, runs, lag-1 autocorrelation, chi-square over bytes, explicit thresholds. Biased raw stream: monobit 64.11 (line 2.576), chi-square 11,488 (line 310.5) β€” FAIL. After extraction: all PASS.
  • Sticky counterexample β€” a source repeating its last bit 80% of the time is unbiased yet fails runs and autocorrelation (|r| = 0.5926): bias and correlation are different diseases.
  • PRNG contrast β€” a classical Mersenne-Twister stream passes all four tests and is labelled quantum_source = False: the standing proof that passing β‰  quantum.
  • TinyML kNN classifier β€” good / marginal / bad from (bias, min-entropy, |autocorrelation|); labels generated by the battery itself. Fair β†’ good, P(1) = 0.47 β†’ marginal, P(1) = 0.25 β†’ bad, sticky β†’ bad, extracted β†’ good.
  • Advisory seats β€” Gemini Argon 4 DECIDER (names-only, tighten-only, sha256 trace), Muse advisor (can never override HOLD), Google Flow plan-only (rendered = False, live = 0).

β βœ… Verified

  • pytest: 44 passed
  • Built-in checks: CHECKS 54/54
  • Deterministic: double-run byte-identical
  • Base image: python:3.12-slim

⁠🏷️ Categories

Science Β· Developer tools Β· Machine learning & AI

  • License: MIT Β© 2026 Darion Kellar
  • Image: credkellar/quantumrandom-lab:latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:316fcf8d0…
Size
41.5 MB
Last updated
17 days ago
docker pull credkellar/quantumrandom-lab:latest