QES-256

A drop-in quantum entropy library. Replace

Math.random()
crypto.getRandomValues()
and friends — all backed by IBM Quantum hardware.

Drop-in · Browser & Node · No build step required

<script src="qes-rng.js"></script>
Architecture

How QES-256 works

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.

⚛️

Quantum Source

Each byte traces to IBM Quantum qubit measurements — physically random, not algorithmic.

🏊

Pool Buffer

512 bytes fetched at startup. Background refill triggers at 20% remaining — no latency in your hot path.

📐

53-bit Precision

QES.random() uses 21 high + 32 low bits to fill the full IEEE-754 mantissa — no precision loss.

API Reference

Methods

Every method is async and matches the exact signature of its native counterpart — swap in QES. and add await. That's it.

QES.random() → Promise<float> replaces Math.random()

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.

Before
const n = Math.random();
// pseudo-random float [0, 1)
After
const n = await QES.random();
// quantum float [0, 1)
QES.randomInt(min, max) → Promise<int> replaces Math.floor(Math.random() * N)

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.

Before
const n = Math.floor(
  Math.random() * (100 - 1)
) + 1;
// biased for large ranges
After
const n = await QES.randomInt(1, 100);
// bias-free, quantum entropy
QES.getRandomValues(typedArray) → Promise<TypedArray> replaces crypto.getRandomValues()

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.

Before
const buf = new Uint8Array(16);
crypto.getRandomValues(buf);
// CSPRNG — not quantum
After
const buf = new Uint8Array(16);
await QES.getRandomValues(buf);
// quantum-sourced bytes
QES.randomUUID() → Promise<string> replaces crypto.randomUUID()

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.

Before
const id = crypto.randomUUID();
// software-seeded UUID
After
const id = await QES.randomUUID();
// quantum-seeded UUID v4
QES.shuffle(array) → Promise<array> replaces lodash shuffle / manual Fisher-Yates

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.

Before
const deck = [1,2,3,4,5];
// manual Fisher-Yates with
// Math.random() — biased
After
const deck = [1,2,3,4,5];
const shuffled =
  await QES.shuffle(deck);
QES.pick(array) → Promise<any> replaces arr[Math.floor(Math.random() * arr.length)]

Picks one random element from an array using quantum entropy. Cleaner than the inline Math.random() idiom and bias-free for any array length.

Before
const items = ['a','b','c'];
const pick =
  items[Math.floor(
    Math.random() * items.length
  )];
After
const items = ['a','b','c'];
const pick =
  await QES.pick(items);
Example

Full integration example

One script tag, zero configuration. The pool warms automatically on page load.

example.html
<!-- 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>

Ready to go quantum?

One script tag. All methods. Backed by IBM Quantum hardware.

Try the Live QRNG Explore EaaS