Dev.to WebDev 🛠 Dev 👁 0

Monte Carlo for a football season: how many simulated seasons you actually need

If you are building any sports simulator, one early question is how many runs you need before the numbers stop moving. For a rare event with true probability p, the standard error of your estimate after n runs is sqrt(p(

If you are building any sports simulator, one early question is how many runs you need before the numbers stop moving. For a rare event with true probability p, the standard error of your estimate after n runs is sqrt(p(1-p)/n).

For a 17-0 season at p = 2% that gives, after 1,000 runs, an error of about 0.44 percentage points, so your estimate of "2%" could sensibly read anywhere from 1.1% to 2.9%. To get the error under 0.1 points you need about 20,000 runs.

const needed = (p, err) => Math.ceil(p * (1 - p) / (err * err));
needed(0.02, 0.001); // 19600

That is cheap in a browser: a season is only 17 weighted coin flips, so even 100,000 seasons run in well under a second if you avoid allocating objects per game. The thing that is expensive is the roster logic, not the dice.

A practical tip is to seed the generator when you want reproducible bug reports, and to leave it unseeded for player-facing play. In 17-0 Game, a free browser NFL season sim, each run draws a fresh season so replays feel different, while the underlying odds stay fixed by your drafted roster.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.