px-rng

Random number service for casino games — dice, roulette, slots, deck shuffles and provably fair rounds — built on an approved NIST SP 800-90A generator, with every outcome written to a tamper-evident journal.

RustHMAC_DRBG · HMAC-SHA-256NIST SP 800-90A Rev. 1 axumCAVP 720/720PractRand · BigCrush · SP 800-22 · Dieharder

Description

Generator

Games

Provably fair rounds

  1. POST /api/round/commit creates a server seed for this round only and returns sha256(server_seed) — show it to the player before play. The round can be bound to a player.
  2. After play, POST /api/round/reveal returns the seed once; the round is then closed.
  3. Result: sha256(server_seed | client_seed | nonce) — first 8 bytes as result_u64, its top 53 bits as result_float. Anyone can recompute it.

Open rounds survive a service restart.

Outcome journal

Every result is written to an append-only journal before it is returned; if it cannot be written, the request fails. Each line carries sha256(previous hash || record), so editing, removing or reordering any record breaks the chain. The verifier checks the chain, recomputes every revealed result and matches each revealed seed to its commitment. Draw requests can carry a round_id that is stored with the result.

Auth

Every endpoint needs Authorization: Bearer <RNG_TOKEN>, compared in constant time. Without a token /api/health answers only {"ok":true}.

Tests

NIST CAVP vectors
720 / 720
HMAC_DRBG SHA-256: no reseed, reseed, prediction resistance
PractRand 0.96
2 TB+
no failures; run continuing to 32 TB
TestU01 BigCrush
4 × 160
2 runs fully clean; 2 single borderline values passed on 5× repeats
NIST SP 800-22
188 / 188
2,000 sequences × 1 Mbit
Dieharder
0 failed
two full runs; every weak result passed on re-run
Game-level checks
10 / 10
chi-square on dice, roulette, slots, shuffles, floats

Statistical batteries

BatteryInputResult
PractRand 0.96service output path, from 1 GB upwardno failures
PractRand 0.96prediction resistance on, 16 GBno anomalies
PractRand 0.96provably fair results, 32 GBno anomalies
TestU01 BigCrushservice output path, three independent runs2 runs all passed; 1 run with one borderline p (PeriodsInStrings), passed 5 repeats
TestU01 BigCrushbit-reversed output (tests the low bits)one borderline p (RandomWalk1), passed 5 repeats
NIST SP 800-22 (STS 2.1.2)2,000 × 1,000,000 bits, all 15 tests188 / 188, lowest proportion 1967 (threshold 1966)
Dieharder 3.31.1full -a, twice0 failed

Game-level checks

CheckDrawsχ²dfpVerdict
Dice 1..660,000,0008.3350.139PASS
Roulette 0..3637,000,00039.70360.309PASS
Slot reel 1..1000100,000,0001010.279990.395PASS
Modulo-bias probe (thirds of 3·2⁶¹)30,000,0000.4020.820PASS
Dice serial pairs36,000,00038.89350.299PASS
52-card shuffle: card × position2,000,0002673.4326520.381PASS
52-card shuffle: top two cards2,000,0002508.9026510.976PASS
Floats [0,1), 1000 bins100,000,000984.019990.626PASS
Provably fair result_float10,000,0001048.649990.134PASS

Throughput

wrk, 4 threads, 10 connections, 15 s, POST /api/range with 1,000 numbers per request, client and service on the same 8-vCPU server.

As deployed (journal on)
≈ 8.9 M numbers/s
8,934 requests/s · p50 0.83 ms · p99 3.13 ms
Journal off
≈ 15.6 M numbers/s
15,641 requests/s · p50 0.44 ms · p99 1.90 ms

Statistical tests show the output cannot be told apart from random by these batteries; they are evidence for an accredited test lab, not a certificate.

API

GET /api/health
Without a token: {"ok":true}. With a token: version, mechanism, reseed policy, per-instance stats, open rounds, journal position.
POST /api/u64
One random u64.
POST /api/range
Body {min,max,count,round_id?} — count integers in [min,max], up to 4,096 per request, unbiased.
POST /api/floats
Body {count,round_id?} — floats in [0,1).
POST /api/shuffle
Body {deck:[…],round_id?} — Fisher–Yates shuffle of the input list.
POST /api/round/commit
Body {round_id,player?} — new server seed for this round; returns server_seed_hash. Duplicate round_id → 409.
POST /api/round/reveal
Body {round_id,player?,client_seed,nonce} — reveals the seed once and returns result_u64, result_float. Unknown or closed round → 404, other player → 403.
POST /api/commit · /api/reveal
Earlier single shared seed, kept for compatibility. New games should use /api/round/*.

Every draw response includes journal_seq, the number of its journal record.

cURL example

curl -s -X POST https://rnd.id5.dev/api/range \
     -H "Authorization: Bearer $RNG_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"min":0,"max":36,"count":5,"round_id":"table-7:spin-1042"}'

Playground

// response will appear here