Say something succeeds with a fixed probability p on every attempt, and each attempt is independent of the others. A rare item that drops once in 137,500 tries is a good example. How many tries do you actually need? The answer is a little surprising, and it only takes a few lines of code.

Two formulas

It is easier to work with failure than success. One attempt fails with probability 1 - p. Every one of n independent attempts fails with probability (1 - p)^n. So the chance of at least one success is:

P(at least one in n) = 1 - (1 - p)^n 

Turn it around to ask how many attempts you need for a target chance (say 50% or 90%):

n = ceil( ln(1 - target) / ln(1 - p) ) 

JavaScript

// chance of at least one success in n attempts const chance = (p, n) => -Math.expm1(n * Math.log1p(-p)); // attempts needed to reach a target chance const attemptsFor = (p, target) => Math.ceil(Math.log1p(-target) / Math.log1p(-p)); const p = 1 / 137500; console.log((chance(p, 1000) * 100).toFixed(2) + "%"); // 0.72% console.log(attemptsFor(p, 0.5)); // 95308 

Math.log1p(x) computes ln(1 + x) accurately when x is tiny, and Math.expm1(x) computes e^x - 1. With p this small, the naive 1 - Math.pow(1 - p, n) loses digits to rounding; the log1p/expm1 pair does not.

Python

import math def chance(p, n): return -math.expm1(n * math.log1p(-p)) def attempts_for(p, target): return math.ceil(math.log1p(-target) / math.log1p(-p)) p = 1 / 137500 print(f"{chance(p, 1000):.2%}") # 0.72% print(attempts_for(p, 0.5)) # 95308 

The numbers for p = 1/137,500

Attempts Chance of at least one
1,000 0.72%
10,000 7.01%
50,000 30.49%
95,308 50.00%
137,500 63.21%
200,000 76.65%

A 90% chance takes about 316,605 attempts.

Why intuition gets this wrong

"One in 137,500" sounds like a promise: do it 137,500 times and you get one. It isn't. At exactly 137,500 attempts the chance is about 63% (that is 1 - 1/e, which shows up whenever n = 1/p). More than a third of people will still have nothing.

The other trap is feeling "due". Each attempt is independent, so someone who has already failed 50,000 times has the same odds on the next attempt as someone starting fresh. The past doesn't push the next result one way or the other.

Check it with a simulation

If you don't trust a formula, simulate it. A rare p needs a lot of trials, so this uses a larger p where the same math applies:

import random, math p, n, runs = 1 / 500, 300, 100_000 hits = sum(any(random.random() < p for _ in range(n)) for _ in range(runs)) print(hits / runs) # simulated, around 0.45 print(-math.expm1(n * math.log1p(-p))) # formula: 0.4512... 

The simulated share lands within a fraction of a percent of the formula, and gets closer as you raise runs.

Takeaways

  • Chance of at least one success: 1 - (1 - p)^n.
  • Attempts for a target chance: ln(1 - target) / ln(1 - p), rounded up.
  • At n = 1/p you are only at about 63%, not 100%.
  • Use log1p / expm1 when p is tiny.

The same three lines work for any "1 in N" event: rare drops, a flaky test that fails 1 time in 1,000, or a lottery-style pick.