← Back to the tool

Foundations · Under the hood

Entropy testing: manual vs. quantum-random

What each button in the tool actually computes, step by step — with the real formulas.

Scope: all 10 of NIST SP 800-90B's non-IID estimators, and what's still missing

NIST SP 800-90B ("Recommendation for the Entropy Sources Used for Random Bit Generation") defines ten different non-IID min-entropy estimators in section 6.3, each catching a different kind of statistical weakness. This tool implements all ten, in the binary-alphabet forms NIST's tool uses for a 1-bit source, ported directly from NIST's own reference implementation (github.com/usnistgov/SP800-90B_EntropyAssessment) rather than re-derived from scratch. Its unit tests run the same sequences through NIST's compiled tool and require agreement to 10 decimal places; the remaining differences come from NIST doing some arithmetic in 80-bit extended precision where a browser has 64-bit doubles.

What it still doesn't do: the IID permutation-testing track, the restart tests, and multi-bit symbols (it takes bits only). It also runs on whatever sequence you type or fetch, up to 250,000 bits, where NIST's own validation runs use at least 1,000,000 samples. Some estimators need a minimum length: Compression needs at least 6,006 bits (more than 1,000 six-bit blocks), MultiMCW at least 4,096, LZ78Y at least 19, and t-Tuple needs one bit value to appear 35 times. Below those lengths the estimator shows as "not run" and, as in NIST's tool, is left out of the overall minimum, which makes that minimum less conservative. On short input the Collision and Compression estimates also read well below 1 bit even for a perfect source: on a 20,000-bit pseudorandom sample, NIST's own tool gives about 0.81 and 0.68. Treat the numbers below as a faithful demonstration of how real entropy estimators work, not a certification result.

Min-entropy is also a stricter, more pessimistic measure than the Shannon entropy most people learn first: Shannon entropy is an average over the whole distribution, while min-entropy asks "how hard is it to guess the single most likely outcome?" — the question that actually matters for a cryptographic key, since an attacker only needs one correct guess. A source can have high Shannon entropy while still leaking enough structure to make min-entropy much lower.

H∞=−log⁡2(max⁡ipi)H_{\infty} = -\log_2\left(\max_i p_i\right)

Min-entropy: driven entirely by the single most probable outcome, unlike Shannon entropy's average over the whole distribution.

Most Common Value Estimate — §6.3.1

The simplest estimator: count how often the most frequent symbol (0 or 1) occurs, then compute a 99%-confidence upper bound on its true probability rather than trusting the raw sample proportion directly — a short or lucky sequence could otherwise look more random than it really is. That conservative probability is converted straight to a min-entropy figure.

pu=min⁡(1, p^+2.5758p^(1−p^)n−1)p_u = \min\left(1,\ \hat{p} + 2.5758\sqrt{\frac{\hat{p}(1-\hat{p})}{n-1}}\right)
H∞=−log⁡2(pu)H_{\infty} = -\log_2(p_u)

Collision Estimate — §6.3.2

Walks the sequence measuring how long it takes to see a repeated pair of consecutive symbols (a "collision"). For a binary alphabet this collapses to a fixed choice: if two consecutive bits already match, that's a 2-bit collision; otherwise the third bit is forced to repeat one of the first two, giving a 3-bit collision. The mean collision length across the whole sequence is converted to a probability, and then to min-entropy, with the same 99%-confidence downward adjustment used above.

Xˉ=1v∑k=1vtkσ^=∑tk2−vXˉ2v−1\bar{X} = \frac{1}{v}\sum_{k=1}^{v} t_k \qquad \hat\sigma = \sqrt{\frac{\sum t_k^2 - v\bar{X}^2}{v-1}}
p=0.5+1.25−0.5 Xˉ′(when Xˉ′<2.5)p = 0.5 + \sqrt{1.25 - 0.5\,\bar{X}'} \quad\text{(when } \bar{X}' < 2.5\text{)}

Markov Estimate — §6.3.3

Models the sequence as a first-order, 2-state Markov chain — tracking not just how often each bit occurs, but how often a 0 is followed by a 0, a 1 by a 0, and so on. From those transition probabilities, the estimator works out the min-entropy of the six most probable 128-bit repeating patterns a chain with those statistics could produce (all-zeros, alternating 0101..., and so on), and reports the worst of the six. A sequence that is unbiased bit-by-bit but has strong bit-to-bit correlation — more random-looking in isolation than it really is — gets caught here even when the Most Common Value estimate above doesn't catch it.

The six candidate patterns evaluated
000...0 (all zeros)       0101...01 (alternating, starting 0)
011...1 (0 then all ones)  100...0 (1 then all zeros)
1010...10 (alternating, starting 1)   111...1 (all ones)

The estimator takes the minimum entropy across all six — the single worst-case pattern the observed transition probabilities could be hiding.

H000…0=−log⁡2P(0)−127log⁡2P(0→0)H_{000\ldots0} = -\log_2 P(0) - 127\log_2 P(0{\to}0)
H0101…=−log⁡2P(0)−64log⁡2P(0→1)−63log⁡2P(1→0)H_{0101\ldots} = -\log_2 P(0) - 64\log_2 P(0{\to}1) - 63\log_2 P(1{\to}0)

Compression Estimate — §6.3.4

Splits the sequence into 6-bit blocks, fills a dictionary with the first 1,000, and then, for every later block, records how far back that same block was last seen. This is Maurer's universal statistical test: a source whose output compresses well repeats blocks sooner than a random one. The estimator solves for the probability p of the most likely block that would give the observed mean log-distance, again lowered by a 99% confidence margin, and reports −log₂(p)/6 bits per bit.

Xˉ=1v∑ilog⁡2(i−last(bi))Xˉ′=Xˉ−2.5758 σ^v\bar{X} = \frac{1}{v}\sum_{i} \log_2\left(i - \text{last}(b_i)\right) \qquad \bar{X}' = \bar{X} - 2.5758\,\frac{\hat\sigma}{\sqrt{v}}
solve E[Xˉ](p)=Xˉ′ for p∈[2−6,1],H=−16log⁡2p\text{solve } E[\bar{X}](p) = \bar{X}' \text{ for } p \in [2^{-6}, 1], \quad H = -\tfrac{1}{6}\log_2 p

t-Tuple and Longest Repeated Substring — §6.3.5 and §6.3.6

t-Tuple counts every overlapping substring of each length i and finds the most common one, Q[i] times, for every length up to the longest whose most common substring still appears at least 35 times. Each length gives a per-bit probability estimate (Q[i]/(n−i+1))^(1/i), and the largest one sets the bound. LRS picks up where t-Tuple stops: for every longer length up to the longest repeated substring, it counts how many pairs of positions hold the same substring, which catches long repeats that occur too rarely for t-Tuple to count.

Both read their counts from a suffix array of the sequence, using the same counting algorithm (Kaufer's) as NIST's code. NIST builds the suffix array with the libdivsufsort library; this tool builds it with a small prefix-doubling routine, which gives the same array.

p^t-Tuple=max⁡1≤i≤t(Q[i]n−i+1)1/ip^LRS=max⁡u≤W≤v(∑j(CW,j2)(n−W+12))1/W\hat{p}_{\text{t-Tuple}} = \max_{1 \le i \le t} \left(\frac{Q[i]}{n-i+1}\right)^{1/i} \qquad \hat{p}_{\text{LRS}} = \max_{u \le W \le v} \left(\frac{\sum_j \binom{C_{W,j}}{2}}{\binom{n-W+1}{2}}\right)^{1/W}

The four predictors — §6.3.7 to §6.3.10

The last four estimators each run a family of simple predictors along the sequence, guessing each bit before looking at it. Within a family, whichever predictor has been right most often so far makes the official guess. MultiMCW (§6.3.7) guesses the most common bit in the last 63, 255, 1,023 or 4,095 bits. Lag (§6.3.8) guesses the bit 1, 2, … or 128 positions back, which catches periodic sources. MultiMMC (§6.3.9) uses Markov models that look at the previous 1 to 16 bits. LZ78Y (§6.3.10) keeps an LZ78-style dictionary of contexts up to 16 bits long and follows the one seen most often.

Each is scored twice. P_global is the overall hit rate, raised to its 99% upper confidence bound. P_local comes from the longest run of correct guesses in a row: it is the per-guess success probability at which a run that long would still have only a 1% chance of appearing. The estimate is −log₂ of the larger of the two, so a predictor that is right in long streaks is penalised even if its overall rate looks ordinary.

NIST's Lag code keeps per-symbol ring buffers for speed; this tool checks all 128 lags directly, in the same order, so ties between lags go the same way and the results are identical.

Pglobal′=p^+2.5758p^(1−p^)N−1,p^=CNP'_{\text{global}} = \hat{p} + 2.5758\sqrt{\frac{\hat{p}(1-\hat{p})}{N-1}}, \quad \hat{p} = \frac{C}{N}
0.99=1−px(r+1−rx) q⋅1xN+1,q=1−p,x=1+qprxr+10.99 = \frac{1 - p x}{(r + 1 - r x)\,q} \cdot \frac{1}{x^{N+1}}, \quad q = 1 - p, \quad x = 1 + q p^{r} x^{r+1}
H=−log⁡2max⁡(Pglobal′, Plocal, 12)H = -\log_2 \max\left(P'_{\text{global}},\ P_{\text{local}},\ \tfrac{1}{2}\right)

The quantum-random source

The "Fetch from ANU QRNG" button calls this site's own server, which in turn calls the Australian National University's Quantum Random Numbers Server (qrng.anu.edu.au) — bits generated by measuring quantum vacuum fluctuations, a genuinely different trust model from a software CSPRNG. The call goes through this site's own API route rather than straight from your browser because ANU's service sends no CORS headers; a direct browser fetch is rejected by the browser itself before the request even reaches ANU. The site's server uses ANU's paid, key-gated Quantum Numbers API (api.quantumnumbers.anu.edu.au) up to a cap of 100 requests a month across all visitors, so a public URL can't run up an unbounded bill; past that, it falls back to ANU's free legacy endpoint, which is heavily rate-limited and being phased out. Occasional failures reflect those upstream services, not a bug here.

Now try it

Back to Entropy testing: manual vs. quantum-random →

Feed in a bit string by hand or pull live bits from a quantum random number generator, then see Shannon entropy alongside all ten NIST SP 800-90B non-IID min-entropy estimators, side by side.