Loot Table Lab
Design and analyse game item drop rates with the binomial and geometric
distributions — then see the maths behind every number.

▶ Try it live · no install, no
sign-up, works offline

Answers the questions you actually have when tuning a loot table:
- “Is a 2% drop over 500 kills going to feel awful?”
- “How many players will finish the grind with nothing?”
- “Where should the pity counter go so only the unluckiest 10% ever hit it?”
- “How likely is a 50-kill dry spell somewhere in a session?” (far likelier
than most people guess — see Droughts)
It is built to work two ways at once: as a genuine tuning aid, and as a way to
see intro-stats distribution theory actually doing something. Every
number on screen can be expanded into the formula that produced it, with the
current values substituted in — not a black box.
Who it is for: game designers tuning drop rates or gacha/pity systems,
students learning the binomial and geometric distributions, and anyone who wants
a trustworthy binomial calculator that does not fall over at large n.
Contents
Running it
Option 1 — just open it. Download or clone the repo and double-click
index.html. No server, no build step, no install, no dependencies. The scripts
are plain <script> tags and there are no network calls at any point, so it
works offline and from a USB stick.
git clone https://github.com/fenton59/loot-table-lab.git
cd loot-table-lab
# then just open index.html
Option 2 — the hosted version. https://fenton59.github.io/loot-table-lab/
Option 3 — serve it locally (only needed if your browser is locked down about
file://):
npx --yes http-server . -p 8080 -o
Running the tests
Node 20 or newer, no dependencies to install — the tests use Node’s built-in
runner:
node --test
106 tests covering the probability engine, the simulator, the formula text and
the chart maths. See Test coverage for what they actually
check. CI runs them on Node 20, 22 and 24.
What each panel does
Define as many items as you like, each with a name, a drop chance p (the
probability it drops on any one attempt) and a number of attempts n (kills,
chests, rolls — whatever your game counts). Selecting an item points every other
panel at it.
The drop-chance slider is log-scaled: half its travel covers 0–3%, because
that is where loot design actually happens. A linear slider would bunch every
interesting rare-drop value into the leftmost few pixels. The number box next to
it takes an exact percentage if you want one.
Tables are kept in localStorage automatically, and Save table / Load
table move them in and out as JSON files.
Binomial model
The full distribution of “how many drops will I get from n attempts”.
- PMF bar chart — the probability of each possible number of drops. Crop
empty tails hides the hundreds of bars with no meaningful probability at large
n; Log scale stretches the vertical axis so you can see the rare tail at all.
- CDF step chart — the running total, i.e. the chance of getting at most k.
- Inspect a specific outcome — pick a k and get P(X = k), P(X ≤ k) and
P(X ≥ k). You can also click a bar on the chart.
Monte Carlo
Actually simulates playthroughs rather than computing them, and overlays the
result on the theoretical PMF so you can watch it converge. The comparison table
puts the empirical mean and variance next to np and np(1−p) with the relative
error.
Runs are seeded, so the same seed always replays the same run — useful when
you want to point at a specific result. Results export to CSV.
Two sampling methods are available. Bernoulli flips a coin for every single
attempt, which is the honest simulation of what the game does. Inverse CDF
draws one random number per playthrough and looks it up in the exact CDF —
statistically identical but far faster. Auto switches to inverse above about
two million coin flips.
Pity & droughts
The distribution of “how long until my first drop”, which is a different
question from the one above and needs the geometric distribution.
- Expected attempts (1/p) plus the median, 90th and 99th percentile waits.
The gap between the mean and the 99th percentile is the reason pity systems
exist.
- Survival curve — the share of players still empty-handed after k attempts.
- Pity counter table — the attempt number at which a hard pity would cover a
given share of your players.
- Drought analysis — the probability of at least one losing streak of a given
length anywhere in a session. This is deliberately contrasted against the
probability of one specific dry stretch, because the two are very different
numbers and the second one is what players actually experience. There is a
Verify by simulation button that checks the exact answer against 20,000
simulated sessions.
Compare
Pin two configurations and see both distributions overlaid, plus a table of what
changed — expected drops, spread, chance of getting nothing, expected wait, and
where the pity counter would have to go.
Show the maths
Under each chart. Shows the general formula, the same formula with your current
numbers substituted in, each intermediate factor, and the result — so it reads as
worked-out maths rather than a black box.
The maths, in plain language
Binomial: how many drops from n attempts?
Each attempt is an independent trial that either drops (probability p) or does
not (probability 1 − p). If X is the number of drops from n attempts, then
X ~ B(n, p) and
P(X = k) = C(n, k) · p^k · (1 − p)^(n − k)
Read it left to right: p^k is the chance that k specific attempts all drop,
(1 − p)^(n−k) is the chance the other n − k all miss, and C(n, k) counts
how many different ways you could choose which k of the n attempts were the
lucky ones.
The mean and variance are
E[X] = np Var(X) = np(1 − p) σ = √(np(1 − p))
E[X] = np is the intuitive one: 500 attempts at 2% averages 10 drops. The
variance is worth more attention than it usually gets — with np = 10 the standard
deviation is 3.13, so a perfectly normal run gives anywhere from 7 to 13 drops.
Geometric: how long until the first drop?
Same coin, different question. If Y is the attempt number on which the first
drop happens, then Y ~ Geo(p):
P(Y = k) = (1 − p)^(k−1) · p k−1 misses, then a hit
P(Y ≤ k) = 1 − (1 − p)^k chance you've seen it by attempt k
E[Y] = 1/p Var(Y) = (1 − p)/p²
At p = 2%, E[Y] = 50 attempts — but σ ≈ 49.5, almost as large as the mean.
That is the design problem in one line: “on average 50 kills” still leaves 10% of
players grinding past 114 and 1% past 228. A pity counter is the fix, and
k = ⌈ln(1 − t) / ln(1 − p)⌉ tells you where to put it to cover a share t of
your players.
Droughts: the number that actually generates complaints
The obvious calculation — (1 − p)^L for a run of L misses — answers “will this
particular stretch be empty”, and it is reassuringly small. But a long session
contains many overlapping stretches, so the chance of hitting such a streak at
some point is much higher. At p = 2% over 500 attempts, a specific 114-miss run
is ~10%, while hitting one somewhere is 68%.
The tool computes the second number exactly, not by simulation. Let A(i) be the
probability of getting through i attempts without ever seeing L misses in a
row. Then
A(i) = 1 for i < L
A(L) = 1 − (1−p)^L
A(i) = A(i−1) − p·(1−p)^L·A(i−L−1) for i > L
and the answer is 1 − A(n). The subtracted term removes exactly those sequences
whose first L-long streak finishes at attempt i — a hit at attempt i−L,
followed by L misses. This is exact and runs in O(n).
Monte Carlo: why the simulation wobbles
The empirical mean of t simulated playthroughs has standard error σ/√t. The
error shrinks like 1/√t, not 1/t — to halve the wobble you need four times
the runs. That is why 1,000 playthroughs look visibly rough against the
theoretical curve and 100,000 look smooth.
How it is built
index.html markup only
style.css dark + light themes, all colours as CSS custom properties
src/
probability.js PURE — binomial & geometric maths, no DOM
simulate.js PURE — seeded RNG and Monte Carlo, no DOM
mathnotes.js PURE — builds the "show the maths" text, no DOM
charts.js canvas rendering only
main.js DOM wiring only
tests/
probability.test.js
simulate.test.js
mathnotes.test.js
charts.test.js
helpers/exact.js independent BigInt reference implementation (tests only)
The three pure modules never touch the DOM, so they can be require()d straight
into Node for testing. They use a small wrapper that exports to module.exports
under Node and to a global under the browser — which is what lets index.html
work by double-clicking, with no build step and no module server.
Numerical correctness
Two classic bugs are specifically designed out.
Factorial overflow. 500! is about 1.2 × 10^1134, which overflows a
double and becomes Infinity; computing C(n,k) as n!/(k!(n−k)!) then gives
Infinity/Infinity = NaN. Everything is instead done in log space with a
memoised log-factorial table, so C(n,k)·p^k·q^(n−k) becomes
exp(logC + k·ln p + (n−k)·ln q). There is a test that demonstrates the naive
version returning NaN where this one returns the right answer.
Precision loss. ln(500!) ≈ 2611, and a double holding 2611 has an ulp of
4.5e-13. Adding 500 logarithms together and then subtracting two such numbers
keeps the absolute error while shrinking the result, which leaked about 3e-12 of
relative error into the PMF. The log-factorial table therefore carries a
compensated correction term (Knuth’s two-sum), which is applied at the
exponential as exp(hi)·(1 + lo). Measured worst-case relative error across a
sweep of large-n cases: 1.5e-13, verified against exact rational arithmetic.
Other deliberate choices:
- CDFs sum from whichever tail is shorter, so hundreds of
1e-40 terms are never
added onto a running total near 1.
1 − (1−p)^k is computed as −expm1(k·log1p(−p)), which keeps its digits when
p is tiny.
p = 0 and p = 1 are handled before any logarithm is taken, since 0 · ln 0
is NaN rather than the 0 the formula wants.
choose() uses BigInt. The usual iterative-product trick avoids overflow but is
not exact — its intermediate values can exceed 2^53 even when the answer does
not, and it drifts by ±1 around C(60,30). A test sweeps the Pascal identity
over ~3,000 cells to keep it honest.
Test coverage
- 10 hand-verified PMF cases including
k=0, k=n, p=0, p=1, n=1, and
large-n cases that overflow naive factorials.
- Large-n results are checked against exact BigInt rational arithmetic
(
tests/helpers/exact.js), which shares no code path with the engine.
- The drought recurrence is checked against brute-force enumeration of all 2^n
sequences for n up to 16 — a completely different algorithm.
- Monte Carlo mean and variance converge to
np and np(1−p) within 5% at
10,000+ trials, across five seeds and five configurations, plus a chi-squared
goodness-of-fit check on the whole histogram shape.
- The geometric simulator’s mean converges to
1/p within 5%, across five seeds.
- Chart column aggregation is checked to tile its range exactly once — no index
covered twice, none dropped.
All statistical assertions use fixed seeds, so a failure is reproducible rather
than a coin flip.
Charts
Plain <canvas>, no charting library — which means no CDN, no network calls, and
full control over the edge cases. Specifically handled:
- n = 2000 — more bars than pixels, so bars are aggregated one per pixel
column keeping the local maximum, instead of aliasing into a moiré pattern.
- p = 0 / p = 1 — all the mass on a single bar and a crop range of width
zero; the range is widened and bars have a 1px minimum body so the spike cannot
vanish.
- n = 1 — two bars, with integer-only axis ticks that do not de-duplicate into
0, 0, 1, 1.
- Rare drops — a log-scale toggle, because a 1e-9 tail is invisible on a
linear axis.
- High-DPI displays, live theme switching, and window resizing all redraw.
Contributing
Issues and pull requests are welcome. The only hard rule is that
src/probability.js, src/simulate.js and src/mathnotes.js stay pure — no
DOM access — so they remain testable in Node.
If you change anything in those three, please add a test. Statistical assertions
should use a fixed seed so failures are reproducible. Run node --test before
opening a PR; CI will run it on Node 20, 22 and 24.
- The pity-system design problem, as seen in Genshin Impact, Overwatch and
Destiny — the gap between
E[Y] = 1/p and the 99th-percentile wait.
- Binomial distribution
B(n, p) and geometric distribution Geo(p) — AQA/Edexcel
A-level Statistics, or any introductory probability course.
Licence
MIT — free to use, modify and redistribute, including commercially.
评论