Papers
Topics
Authors
Recent
Search
2000 character limit reached

Fast Loaded Dice Roller

Updated 10 July 2026
  • 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 (a1,,an)(a_1,\dots,a_n) with m=i=1naim=\sum_{i=1}^n a_i, and the algorithm returns i{1,,n}i\in\{1,\dots,n\} with probability ai/ma_i/m (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 BFlip{0,1}B\sim Flip\in\{0,1\} (Saad et al., 2020). Given positive integer weights

(a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,

the required output law is

pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.

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 nn-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

H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),

and the Knuth–Yao theorem gives entropy-optimal discrete-distribution generating trees m=i=1naim=\sum_{i=1}^n a_i0 satisfying

m=i=1naim=\sum_{i=1}^n a_i1

where m=i=1naim=\sum_{i=1}^n a_i2 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 m=i=1naim=\sum_{i=1}^n a_i3-sided die using one m=i=1naim=\sum_{i=1}^n a_i4-coin and m=i=1naim=\sum_{i=1}^n a_i5 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 m=i=1naim=\sum_{i=1}^n a_i6 directly. Instead, it constructs a dyadic proposal distribution m=i=1naim=\sum_{i=1}^n a_i7 that can be represented by a finite-depth entropy-optimal DDG tree and then uses rejection sampling (Saad et al., 2020).

Let

m=i=1naim=\sum_{i=1}^n a_i8

FLDR defines an extended proposal distribution on m=i=1naim=\sum_{i=1}^n a_i9 outcomes: i{1,,n}i\in\{1,\dots,n\}0 The extra i{1,,n}i\in\{1,\dots,n\}1-st state is a reject state (Saad et al., 2020). Because i{1,,n}i\in\{1,\dots,n\}2 is dyadic, its entropy-optimal DDG tree has depth exactly i{1,,n}i\in\{1,\dots,n\}3 (Saad et al., 2020).

The online procedure is conceptually simple. FLDR first samples i{1,,n}i\in\{1,\dots,n\}4 using an entropy-optimal sampler for the dyadic proposal. If i{1,,n}i\in\{1,\dots,n\}5, it returns i{1,,n}i\in\{1,\dots,n\}6; if i{1,,n}i\in\{1,\dots,n\}7, it rejects and restarts (Saad et al., 2020). The rejection constant is

i{1,,n}i\in\{1,\dots,n\}8

since for i{1,,n}i\in\{1,\dots,n\}9,

ai/ma_i/m0

The acceptance probability is therefore

ai/ma_i/m1

which is always greater than ai/ma_i/m2 because ai/ma_i/m3, and so the expected number of proposal rounds is

ai/ma_i/m4

(Saad et al., 2020).

This construction is exact by standard rejection-sampling reasoning. Conditioning on acceptance yields

ai/ma_i/m5

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

ai/ma_i/m6

preprocessing inspects the binary digits of the integers ai/ma_i/m7 across levels ai/ma_i/m8 (Saad et al., 2020).

Two arrays are constructed:

Structure Role
ai/ma_i/m9 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

BFlip{0,1}B\sim Flip\in\{0,1\}0

Each fair bit BFlip{0,1}B\sim Flip\in\{0,1\}1 updates

BFlip{0,1}B\sim Flip\in\{0,1\}2

If BFlip{0,1}B\sim Flip\in\{0,1\}3, a leaf has been reached at level BFlip{0,1}B\sim Flip\in\{0,1\}4. If BFlip{0,1}B\sim Flip\in\{0,1\}5, that label is returned; if BFlip{0,1}B\sim Flip\in\{0,1\}6, the run is rejected and BFlip{0,1}B\sim Flip\in\{0,1\}7 is reset to BFlip{0,1}B\sim Flip\in\{0,1\}8. Otherwise the path continues to the next level via

BFlip{0,1}B\sim Flip\in\{0,1\}9

(Saad et al., 2020).

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 (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,0 indexes the current position among these slots, while (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,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 (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,2 as the number of leaves in row (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,3 and (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,4 as the output number stored at node (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,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 (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,6 of FLDR has at most

(a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,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

(a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,8

Thus FLDR consumes at most (a1,,an),i=1nai=m,(a_1,\dots,a_n),\qquad \sum_{i=1}^n a_i = m,9 bits more than the information-theoretically optimal expected rate (Saad et al., 2020). The proof decomposes the expected-bit overhead into three terms: pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.0 where pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.1 is the Knuth–Yao slack for the dyadic proposal pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.2 (Saad et al., 2020). Using pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.3, the paper bounds these three terms respectively by pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.4, pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.5, and pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.6, yielding the total pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.7 (Saad et al., 2020).

These guarantees position FLDR between entropy-optimal DDG sampling and simpler exact samplers. Knuth–Yao achieves

pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.8

but may require exponentially large space (Saad et al., 2020). The exact interval sampler has a tighter theoretical additive gap of pi=aim,i{1,,n}.p_i = \frac{a_i}{m},\qquad i\in\{1,\dots,n\}.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

nn0

starting from nn1, updating by one fair bit via

nn2

and recycling rejected mass by

nn3

They show that the expected number of flips for a fair nn4-sided die is at most

nn5

(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 nn6 is carried across calls, with invariant nn7, updated by refilling

nn8

and by rejection recycling

nn9

when H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),0, where H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),1 and H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),2 (Ömer et al., 2014). They show that the entropy loss per iteration is

H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),3

and the expected waste per completed roll is

H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),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 H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),5-coin plus fair flips. It proves that a fair H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),6-sided die can be simulated using

H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),7

(Viglietta, 2015). The paper itself emphasizes that this is not the usual unbiased-bit FLDR setting, because it assumes access to a special H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),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 H(p)=i=1npilog(1/pi),H(p)=\sum_{i=1}^{n} p_i \log(1/p_i),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,

m=i=1naim=\sum_{i=1}^n a_i00

where m=i=1naim=\sum_{i=1}^n a_i01 is the unknown source distribution (Zhou et al., 2012). This is related to FLDR conceptually, but it solves the inverse problem: loaded die m=i=1naim=\sum_{i=1}^n a_i02 unbiased bits, not unbiased bits m=i=1naim=\sum_{i=1}^n a_i03 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 m=i=1naim=\sum_{i=1}^n a_i04 faster than dyadic lookup-table rejection, up to m=i=1naim=\sum_{i=1}^n a_i05 faster than dyadic binary-search rejection, up to m=i=1naim=\sum_{i=1}^n a_i06 faster than the interval sampler, and up to m=i=1naim=\sum_{i=1}^n a_i07 faster than the alias method at low entropies (Saad et al., 2020).

The experiments use random frequency distributions over m=i=1naim=\sum_{i=1}^n a_i08 dimensions with total mass m=i=1naim=\sum_{i=1}^n a_i09, as well as preprocessing benchmarks varying m=i=1naim=\sum_{i=1}^n a_i10 with m=i=1naim=\sum_{i=1}^n a_i11 (Saad et al., 2020). The reported metrics include sampler memory usage, preprocessing time, runtime per sample or time for m=i=1naim=\sum_{i=1}^n a_i12 samples, and PRNG calls (Saad et al., 2020). For m=i=1naim=\sum_{i=1}^n a_i13 samples from m=i=1naim=\sum_{i=1}^n a_i14-dimensional distributions, FLDR’s buffered fair-bit implementation required from m=i=1naim=\sum_{i=1}^n a_i15 PRNG calls at entropy m=i=1naim=\sum_{i=1}^n a_i16 bit to m=i=1naim=\sum_{i=1}^n a_i17 calls at entropy m=i=1naim=\sum_{i=1}^n a_i18 bits, compared with m=i=1naim=\sum_{i=1}^n a_i19 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 m=i=1naim=\sum_{i=1}^n a_i20 and m=i=1naim=\sum_{i=1}^n a_i21, with the proposal distribution

m=i=1naim=\sum_{i=1}^n a_i22

and a reset to the root whenever the extra reject side m=i=1naim=\sum_{i=1}^n a_i23 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 m=i=1naim=\sum_{i=1}^n a_i24, 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).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Fast Loaded Dice Roller.