Fast Loaded Dice Roller
- Fast Loaded Dice Roller is a discrete sampling algorithm that generates exact samples from a weighted distribution using unbiased random bits.
- It employs a dyadic proposal distribution with rejection sampling to achieve an additive entropy gap of less than 6 bits above Shannon's lower bound.
- FLDR features linear-time preprocessing and compact data structures, delivering significant speed and memory efficiency gains over traditional methods.
The Fast Loaded Dice Roller (FLDR) is an exact discrete sampling algorithm for generating an integer from a finite distribution using only independent unbiased random coin flips. In its standard formulation, the input is a vector of positive integer weights with , and the algorithm returns with probability (Saad et al., 2020). FLDR belongs to the random-bit model, where exactness and entropy cost are both explicit design objectives; its distinguishing feature is the combination of a compact sampler representation, linear-time preprocessing, and a provable additive gap of less than $6$ bits above the Shannon lower bound on expected random-bit consumption (Saad et al., 2020).
1. Definition and problem formulation
FLDR addresses the classical problem of exact sampling from a finite discrete distribution when the only primitive source of randomness is an i.i.d. sequence of fair bits (Saad et al., 2020). Given positive integer weights
the required output law is
This is the “loaded dice” problem in the exact random-bit setting: one must generate samples from an arbitrary finite-support discrete distribution, not merely a uniform -way choice (Saad et al., 2020).
The random-bit model is stricter than the real-RAM or floating-point model because it simultaneously tracks exactness and entropy usage (Saad et al., 2020). In this setting, the information-theoretic lower bound on expected random-bit consumption is the Shannon entropy
and the Knuth–Yao theorem gives entropy-optimal discrete-distribution generating trees 0 satisfying
1
where 2 is the number of unbiased bits consumed (Saad et al., 2020). FLDR is motivated by the fact that such entropy-optimal samplers can require exponentially large space relative to the encoded input size (Saad et al., 2020).
A central point in the literature is that FLDR should not be conflated with methods for fair dice only. Ömer and Pacher study uniform generation with entropy recycling across rolls (Ömer et al., 2014), Huber and Vargas study exact fair-die generation from fair bits with a simplified Knuth–Yao construction (Huber et al., 2024), and a different 2015 construction studies simulation of a fair 3-sided die using one 4-coin and 5 fair coin flips (Viglietta, 2015). Those works are closely related conceptually, but FLDR is specifically the weighted, arbitrary-distribution case (Saad et al., 2020).
2. Construction via a dyadic proposal distribution
The core idea of FLDR is to avoid building the entropy-optimal sampler for the target distribution 6 directly. Instead, it constructs a dyadic proposal distribution 7 that can be represented by a finite-depth entropy-optimal DDG tree and then uses rejection sampling (Saad et al., 2020).
Let
8
FLDR defines an extended proposal distribution on 9 outcomes: 0 The extra 1-st state is a reject state (Saad et al., 2020). Because 2 is dyadic, its entropy-optimal DDG tree has depth exactly 3 (Saad et al., 2020).
The online procedure is conceptually simple. FLDR first samples 4 using an entropy-optimal sampler for the dyadic proposal. If 5, it returns 6; if 7, it rejects and restarts (Saad et al., 2020). The rejection constant is
8
since for 9,
0
The acceptance probability is therefore
1
which is always greater than 2 because 3, and so the expected number of proposal rounds is
4
This construction is exact by standard rejection-sampling reasoning. Conditioning on acceptance yields
5
so the target distribution is reproduced without approximation (Saad et al., 2020). A plausible implication is that FLDR’s main innovation is not a new exactness principle, but a particularly effective reconciliation of exact rejection sampling with a compact dyadic proposal representation.
3. Data structures, preprocessing, and online sampling
FLDR does not store a pointer-based binary tree. Instead, it stores a compact encoding of the DDG tree associated with the dyadic proposal distribution (Saad et al., 2020). After setting
6
preprocessing inspects the binary digits of the integers 7 across levels 8 (Saad et al., 2020).
Two arrays are constructed:
| Structure | Role |
|---|---|
| 9 | number of leaf nodes at level $6$0 |
| $6$1 | labels of those leaves at level $6$2, in increasing order |
The preprocessing algorithm is linear in the $6$3 bit matrix and thus runs in $6$4 time; storage is also $6$5 (Saad et al., 2020). The paper emphasizes that this is linear in the encoded input size (Saad et al., 2020). On 64-bit machines, $6$6, so preprocessing is effectively linear in $6$7 in practice (Saad et al., 2020).
The online sampler maintains two state variables: $6$8, the current level, and $6$9, the current index among residual internal nodes at that level (Saad et al., 2020). Initialization is
0
Each fair bit 1 updates
2
If 3, a leaf has been reached at level 4. If 5, that label is returned; if 6, the run is rejected and 7 is reset to 8. Otherwise the path continues to the next level via
9
This representation is best understood as an implicit DDG traversal. At each level, some positions correspond to leaves and the remaining positions correspond to internal nodes. The variable 0 indexes the current position among these slots, while 1 specifies how many of them are terminal at that level (Saad et al., 2020). The same binary-tree viewpoint is used in the later verification treatment, which describes 2 as the number of leaves in row 3 and 4 as the output number stored at node 5 (Batz et al., 8 Sep 2025).
4. Theoretical guarantees
FLDR’s principal theoretical results are a linear-size sampler bound and a constant additive entropy-gap bound (Saad et al., 2020).
The size theorem states that the DDG tree 6 of FLDR has at most
7
nodes (Saad et al., 2020). This is the key structural contrast with the entropy-optimal Knuth–Yao tree for the original target distribution, which can be exponentially larger than the input representation for some rational distributions (Saad et al., 2020).
The entropy theorem states that
8
Thus FLDR consumes at most 9 bits more than the information-theoretically optimal expected rate (Saad et al., 2020). The proof decomposes the expected-bit overhead into three terms: 0 where 1 is the Knuth–Yao slack for the dyadic proposal 2 (Saad et al., 2020). Using 3, the paper bounds these three terms respectively by 4, 5, and 6, yielding the total 7 (Saad et al., 2020).
These guarantees position FLDR between entropy-optimal DDG sampling and simpler exact samplers. Knuth–Yao achieves
8
but may require exponentially large space (Saad et al., 2020). The exact interval sampler has a tighter theoretical additive gap of 9 bits, but the FLDR paper reports much faster implementations for FLDR (Saad et al., 2020). This suggests that FLDR’s design criterion is not absolute optimality in one dimension, but a specific balance among exactness, entropy efficiency, preprocessing cost, and memory.
The verification literature reinforces this interpretation. A 2025 paper describes FLDR as a “near-optimal exact sampler” whose key motivation is to eliminate the exponential memory needs of a standard optimal-runtime sampler (Batz et al., 8 Sep 2025). That formulation closely matches the tradeoff already made explicit in the original FLDR analysis (Saad et al., 2020).
5. Relation to fair-die algorithms and neighboring methods
FLDR is part of a broader line of work on exact sampling from unbiased bits, but it is not interchangeable with fair-die methods.
For the uniform case, Huber and Vargas give a state-based algorithm with invariant
0
starting from 1, updating by one fair bit via
2
and recycling rejected mass by
3
They show that the expected number of flips for a fair 4-sided die is at most
5
(Huber et al., 2024). That algorithm is essentially a simplified Knuth–Yao realization specialized to the uniform case, and its general-distribution extension is described as more abstract and less implementation-friendly (Huber et al., 2024). Relative to FLDR, it isolates the particularly clean structure of the uniform problem.
Ömer and Pacher study another fair-die setting in which an entropy reservoir 6 is carried across calls, with invariant 7, updated by refilling
8
and by rejection recycling
9
when 0, where 1 and 2 (Ömer et al., 2014). They show that the entropy loss per iteration is
3
and the expected waste per completed roll is
4
which decreases as the reservoir grows (Ömer et al., 2014). This is not FLDR, but it belongs to the same entropy-recycling ecosystem.
A different 2015 note studies an exact simulation problem with an additional primitive: one flip of a 5-coin plus fair flips. It proves that a fair 6-sided die can be simulated using
7
(Viglietta, 2015). The paper itself emphasizes that this is not the usual unbiased-bit FLDR setting, because it assumes access to a special 8 source (Viglietta, 2015).
There is also a dual line of work that should be distinguished from FLDR. Zhou and Bruck study extraction of perfect unbiased bits from an i.i.d. loaded 9-sided die by reducing the problem to extraction from a biased binary coin via a binarization tree (Zhou et al., 2012). Their theorem states that any valid fixed-input binary extractor can be transformed into a loaded-die extractor preserving asymptotic optimality,
00
where 01 is the unknown source distribution (Zhou et al., 2012). This is related to FLDR conceptually, but it solves the inverse problem: loaded die 02 unbiased bits, not unbiased bits 03 loaded die samples.
6. Empirical performance, verification, and significance
The FLDR paper reports substantial empirical gains over several exact baseline samplers. Its abstract states that FLDR is “2x-10x faster in both preprocessing and sampling” than multiple baseline algorithms, including alias and interval samplers, and that it uses “up to 10000x less space than the information-theoretically optimal sampler” (Saad et al., 2020). In the body, the detailed comparisons are more granular: FLDR is reported as up to 04 faster than dyadic lookup-table rejection, up to 05 faster than dyadic binary-search rejection, up to 06 faster than the interval sampler, and up to 07 faster than the alias method at low entropies (Saad et al., 2020).
The experiments use random frequency distributions over 08 dimensions with total mass 09, as well as preprocessing benchmarks varying 10 with 11 (Saad et al., 2020). The reported metrics include sampler memory usage, preprocessing time, runtime per sample or time for 12 samples, and PRNG calls (Saad et al., 2020). For 13 samples from 14-dimensional distributions, FLDR’s buffered fair-bit implementation required from 15 PRNG calls at entropy 16 bit to 17 calls at entropy 18 bits, compared with 19 PRNG calls for the floating-point samplers included in that comparison (Saad et al., 2020).
The later verification literature treats FLDR as a representative case study for probabilistic-program verification. A 2025 paper verifies FLDR using distributional loop invariants, modeling probabilistic programs as distribution transformers and proving partial correctness unconditionally and total correctness under an assumption of almost-sure termination (Batz et al., 8 Sep 2025). In that treatment, FLDR is expressed as a probabilistic loop over the binary-tree tables 20 and 21, with the proposal distribution
22
and a reset to the root whenever the extra reject side 23 is encountered (Batz et al., 8 Sep 2025).
The invariant used in that proof is notably more complex than the invariant for the fair Fast Dice Roller. It combines bounds on the current tree position, row-wise uniformity of internal nodes, row-wise uniformity of leaf nodes, and a “current plus future mass” constraint for each output value (Batz et al., 8 Sep 2025). This suggests that FLDR’s algorithmic economy does not eliminate proof complexity; rather, it shifts it into an explicit probabilistic accounting of proposal mass, rejection, and residual output budget.
From a broader perspective, FLDR occupies a specific niche in exact discrete sampling. It is not the entropy-optimal sampler in the absolute Knuth–Yao sense, and it is not the simplest possible rejection scheme. Its significance lies in showing that one can retain exactness, achieve expected bit consumption within a universal constant of 24, preprocess in linear time, and store the sampler in space linear in the encoded input size (Saad et al., 2020). That combination explains why subsequent work treats FLDR both as a practical default for exact weighted sampling and as a canonical example for formal verification of discrete probabilistic algorithms (Saad et al., 2020, Batz et al., 8 Sep 2025).