Loot tables (weighted random)
Make rare things rare, on purpose.
A plain random pick gives every item the same chance. A loot table gives each entry a weight, so common items drop often and legendaries rarely. Add pity timers so an unlucky player is not stuck forever, and seed the random so the same chest gives the same result for testing.
Try this: Open chests one at a time, then 100 at once. The live tally drifts toward the table weights (60 / 28 / 10 / 2 %). Turn on the pity timer and a Legendary is guaranteed after 30 dry chests.
Pure weights. Open chests.
Prompt bit
Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.
Build weighted loot tables: give each entry a weight, roll a random number times the total weight, guarantee a rare after 30 rolls without one, show the drop result within 0.5 s, and drop nothing instead of crashing when a table is empty.
Implement data-driven loot tables (2D or 3D, any engine). Define tables in data (JSON, ScriptableObject, Resource): entries with item id or nested table, weight, and min/max quantity. To roll: total = sum of weights; r = random() * total; walk entries subtracting weights until r < weight. Support nested tables (a "rare" entry that rolls the rare table), guaranteed drops, and a "nothing" entry. Add a pity system: count rolls since the last rare and raise its weight or force it at a cap (for example 30 rolls). Use a seeded RNG per run or per chest for reproducibility and testing. Show drop rates in a debug tool by simulating 10,000 rolls. Handle empty tables and zero total weight.
Where it's used
- RPGs and looter shooters: rarity tiers
- Roguelikes: item and room rewards
- Gacha and card packs: rates and pity
- Survival games: resource drops
- Enemy spawns: weighted spawn tables
Common mistakes
Using percentages that must add up to 100 and break when you add an item, rolling with uniform random, no pity so streaks feel unfair, hard-coded tables in code, and crashing on empty tables.
Writing this with an AI assistant? See our best AI coding assistants for game developers.
Missing a concept? Request one.



