Sub topic 13
Pity Timers and Bad-Luck Protection
This chapter assumes you know basic probability, expected value, and the gambler's fallacy. It also assumes you have seen weighted tables and shuffle bags and can read short Python programs. Here you will build pity timers, measure what they do to a drop rate, and avoid the common mistakes.
The problem a pity timer solves
A weighted drop with a 2% chance per attempt has an expected wait of 50 attempts. Expected value describes the average, not what any one player sees. Each attempt is independent, so the number of attempts before the first success follows a geometric distribution. Many players wait far longer than 50 attempts.
The chance of failing 100 times in a row at 2% is 0.98^100, which is about 13%. About one player in eight gets nothing after 100 attempts, even though the system is working as designed. Those players feel cheated, and some of them quit.
A pity timer is a counter of attempts since the last success. When the counter reaches a limit, the next attempt succeeds. This puts a hard cap on the worst case and leaves the average experience mostly unchanged.
A hard pity timer
The code below uses the same logic as the spine's example. Each attempt increments a counter. A success, whether natural or forced, resets it.
import random
def open_pack(rng, state, base_chance=0.02, pity_limit=50):
state['attempts'] += 1
if state['attempts'] >= pity_limit or rng.random() < base_chance:
state['attempts'] = 0
return True
return False
rng = random.Random(3)
state = {'attempts': 0}
results = [open_pack(rng, state) for _ in range(200)]
print(sum(results))Two details matter:
- The counter lives in
state, not in the function. The state must be saved with the player's data, or players lose their protection when they restart the game. - The counter resets on every success, including natural ones. If you only reset it on forced successes, a lucky player could still hit pity right after a win.
What the cap does to the average
With a base chance of 2% and a limit of 50, a natural success is no longer allowed to take longer than 50 attempts. The expected wait drops below 50, so the real drop rate is higher than the 2% you wrote down. You can compute it. The wait is the minimum of a geometric variable and 50, which gives an expected wait of the sum of 0.98^k for k from 0 to 49.
base_chance = 0.02
pity_limit = 50
expected_wait = sum((1 - base_chance) ** k for k in range(pity_limit))
effective_rate = 1 / expected_wait
print(round(expected_wait, 2))
print(round(effective_rate, 4))The expected wait is about 31.8 attempts, so the effective rate is about 3.1%. The pity timer raised the rate by more than half. If your economy was balanced around 2%, you have just given away a lot of rare items. To keep a target rate, lower the base chance, raise the limit, or accept the higher rate on purpose.
Soft pity
A hard pity timer has a visible cliff: nothing happens for 49 attempts, then success is certain. Players learn the cliff and plan around it. Some stop trying until they can "buy into" the guarantee. A soft pity timer raises the chance gradually once the counter passes a threshold, then forces success at the limit.
import random
def soft_pity_chance(attempts, base=0.02, soft_start=30, hard_limit=50):
if attempts >= hard_limit:
return 1.0
if attempts < soft_start:
return base
steps = attempts - soft_start + 1
ramp = (1.0 - base) / (hard_limit - soft_start + 1)
return min(1.0, base + ramp * steps)
def open_pack_soft(rng, state):
state['attempts'] += 1
if rng.random() < soft_pity_chance(state['attempts']):
state['attempts'] = 0
return True
return False
rng = random.Random(5)
state = {'attempts': 0}
gaps, since = [], 0
for _ in range(20000):
since += 1
if open_pack_soft(rng, state):
gaps.append(since)
since = 0
print(len(gaps), max(gaps), round(sum(gaps) / len(gaps), 1))The chance climbs in equal steps from the base value at attempt 30 to 100% at attempt 50. Most successes then arrive between attempts 30 and 50, so the gaps cluster instead of trailing off in a long tail. The maximum gap is still 50.
Design decisions
| Decision | Options | Trade-off |
|---|---|---|
| Limit | Low or high | A low limit protects players but inflates the real rate. A high limit protects fewer of them. |
| Shape | Hard or soft | Hard is easy to explain and test. Soft hides the cliff and feels more natural. |
| Reset | On any success or only on target items | Resetting on any success is simple. Resetting only on the target item is stricter, and players must understand it. |
| Visibility | Shown or hidden | A shown counter builds trust but invites planning around it. A hidden one stays invisible but can look unfair. |
| Scope | Per item, per banner, per player | Wider scope gives simpler rules. Narrower scope gives finer control. |
Common errors
- Forgetting the effective rate. Adding pity without changing the base chance silently raises the drop rate. Always compute it, as in the earlier snippet.
- Not persisting the counter. If the counter is stored only in memory, a restart resets it. In a game with server-side drops, store it on the server, since a client-side counter can be edited.
- Off-by-one limits. In the code,
attemptsis incremented before the check, so a limit of 50 means success on the 50th attempt. If you check before incrementing, success lands on the 51st. Write a test for the boundary. - Shared counters across unrelated pools. One counter for several loot tables lets a success in one reset the protection of the others. Use one counter per pool.
- Stacking protections. A pity timer on top of a shuffle bag and a catch-up bonus can compound. Measure the combined effect instead of reasoning about each system alone.
- Misreading the gambler's fallacy. The pity timer works because the system tracks history on purpose. The underlying roll is still independent. Do not tell players that they are "due" unless the system really has a counter behind it.
Verifying with simulation
Run many simulated players and look at the distribution of gaps, not only the mean. Compare the worst case with and without pity.
import random
def gaps_for(pity_limit, base=0.02, successes=5000, seed=11):
rng = random.Random(seed)
attempts = 0
since = 0
gaps = []
while len(gaps) < successes:
attempts += 1
since += 1
if since >= pity_limit or rng.random() < base:
gaps.append(since)
since = 0
return gaps
for limit in (10**9, 80, 50, 30):
g = gaps_for(limit)
mean = sum(g) / len(g)
print(limit, round(mean, 1), max(g))A limit of 10**9 acts as "no pity". Its mean will be near 50, but its maximum gap will be several hundred attempts. The limited versions show a smaller mean and a maximum equal to the limit. Because the generator is seeded, the same output appears on every run, which makes the test usable in automated checks.
Pity and fairness to players
A pity timer is a promise. Publish the rule where players can see it, or at least do not contradict it. Hidden pity that the community reverse-engineers through data can damage trust more than a disclosed rule would. In some regions, the published odds of paid random rewards are regulated, so check the rules that apply to you before shipping.
Exercise
A drop has a base chance of 5% per attempt and a hard pity limit of 20, with the counter incremented before the check and reset on every success. (a) What is the longest possible gap between successes? (b) Write the expression for the expected wait, and say whether it is above or below 20 attempts, the expected wait with no limit.
Show answer
(a) The longest gap is 20 attempts, because the 20th attempt always succeeds. (b) The expected wait is the sum of 0.95^k for k from 0 to 19, which is about 12.8 attempts. That is below the 20 attempts of the uncapped game (1 / 0.05), so the effective rate is about 7.8%, higher than the written 5%.
Exercise
Your designers want a 2% average drop rate and a worst-case gap of 100 attempts. Why can't you simply set the base chance to 2% and the limit to 100? What would you change, and how would you check it?
Show answer
With a limit of 100, the cap makes the average wait shorter than 50, so the effective rate ends up above 2%. Lower the base chance until the sum of (1 - base)^k for k from 0 to 99 equals 50 (about 1% gives roughly 63, and about 1.4% gives close to 50, so search in that range). Then confirm the result with a seeded simulation that reports the mean gap and the maximum gap.