A drop-in quantum entropy library. Replace
Math.random()crypto.getRandomValues()QES-256 pre-fetches 512 quantum bytes from the STEADYWATCH™ entropy endpoint and serves them synchronously from an in-memory pool — so your code stays fast even though the entropy source is a quantum computer.
Each byte traces to IBM Quantum qubit measurements — physically random, not algorithmic.
512 bytes fetched at startup. Background refill triggers at 20% remaining — no latency in your hot path.
QES.random() uses 21 high + 32 low bits to fill the full IEEE-754 mantissa — no precision loss.
Every method is async and matches the exact signature of its native counterpart — swap in QES. and add await. That's it.
Returns a quantum float in [0, 1) using 53 bits of entropy — 21 high bits and 32 low bits combined to fill the full IEEE-754 double mantissa without precision loss.
const n = Math.random(); // pseudo-random float [0, 1)
const n = await QES.random(); // quantum float [0, 1)
Returns an integer in [min, max) using rejection sampling to eliminate modulo bias — the same flaw that makes Math.random() subtly non-uniform for large ranges.
const n = Math.floor( Math.random() * (100 - 1) ) + 1; // biased for large ranges
const n = await QES.randomInt(1, 100); // bias-free, quantum entropy
Fills a TypedArray in-place with quantum random bytes and returns it — identical signature to crypto.getRandomValues(). Works with Uint8Array, Uint32Array, and all other typed array types.
const buf = new Uint8Array(16); crypto.getRandomValues(buf); // CSPRNG — not quantum
const buf = new Uint8Array(16); await QES.getRandomValues(buf); // quantum-sourced bytes
Generates a RFC 4122 v4 UUID using 16 quantum-sourced bytes. Version and variant bits are set correctly per spec. Every UUID is rooted in hardware randomness — not a software PRNG.
const id = crypto.randomUUID(); // software-seeded UUID
const id = await QES.randomUUID(); // quantum-seeded UUID v4
Returns a new shuffled array using the Fisher-Yates algorithm driven by quantum entropy. The original array is never mutated. Each swap index is drawn from QES.randomInt() — bias-free at every step.
const deck = [1,2,3,4,5]; // manual Fisher-Yates with // Math.random() — biased
const deck = [1,2,3,4,5]; const shuffled = await QES.shuffle(deck);
Picks one random element from an array using quantum entropy. Cleaner than the inline Math.random() idiom and bias-free for any array length.
const items = ['a','b','c']; const pick = items[Math.floor( Math.random() * items.length )];
const items = ['a','b','c']; const pick = await QES.pick(items);
One script tag, zero configuration. The pool warms automatically on page load.
<!-- 1. Include the library --> <script src="qes-rng.js"></script> <script> async function run() { // Float [0, 1) const f = await QES.random(); // Integer [1, 7) — dice roll const die = await QES.randomInt(1, 7); // Fill a key buffer const key = new Uint8Array(32); await QES.getRandomValues(key); // Quantum UUID const id = await QES.randomUUID(); // Shuffle a deck const deck = [1,2,3,4,5,6,7,8]; const shuffled = await QES.shuffle(deck); // Pick one at random const winner = await QES.pick(['Alice', 'Bob', 'Carol']); } run(); </script>
One script tag. All methods. Backed by IBM Quantum hardware.