[E] [S] Validating a Monte Carlo betting simulator: methodology and edge cases

I spent the last week building and testing a Monte Carlo simulator for casino betting systems (specifically, the Martingale strategy on roulette). Thought I'd share some methodological learnings that might be useful to this sub, since I learned the hard way.

The problem: validating a betting simulator is tricky because the "real" answer is just math, but if your code bugs it silently, you get confident wrong results.

What I did:

  1. Closed-form validation first. The theoretical EV of every bet (e.g., Martingale on roulette) is a formula. I calculated it by hand for simple cases (small sample, fixed sequence) and verified the simulator matched *exactly* before scaling to 1M+ runs.
  2. Seed reproducibility. Used a seeded PRNG (xorshift128) so identical seeds produce identical byte sequences. Caught bugs where I was accidentally reseeding in a loop.
  3. Bootstrap on subsets. Ran 10k sessions with 500 spins each, then 100k sessions with 100 spins each, and checked that the empirical distribution of final bankroll converged as expected. Different parameterizations, same theoretical edge — this confirmed the edge wasn't a code artifact.
  4. Edge case trapping. Bankroll hitting exactly the table limit, ruin vs. just running out of balance, floating-point precision on EV calculations (I use 1e-6 tolerance on unit tests).

Result: 1M sessions run in ~2 seconds on a phone. Empirical quiescence rate matches theoretical prediction within 0.5%.

Question for the sub: if you're validating a stochastic simulator, is this pipeline standard, or am I overthinking it? I've seen papers skip the closed-form check and jump straight to "run 1M iterations and compare to literature" — but that feels risky to me.

Tool is here: https://optimalplay.pages.dev/es/roulette

Any feedback on methodology welcome.

reddit.com
u/Extension-Ad8058 — 7 days ago
▲ 3 r/nextjs+1 crossposts

I built a casino math PWA with Next.js 15, Cloudflare Workers, and zero backend

I just shipped a side project I've been building: a progressive web app that teaches the math behind casino games (expected value, variance, Monte Carlo simulations) — all running client-side, no backend, no data collection.

Tech stack if anyone's curious:

- Next.js 15 (App Router) deployed on Cloudflare Pages via next-on-pages

- All Monte Carlo simulations run in Web Workers — no server calls

- Dexie (IndexedDB) for local-only session journaling

- next-intl for ES/EN i18n

- Fully installable as a PWA on Android

Modules live: Blackjack basic strategy advisor, Roulette EU vs US comparator + Martingale simulator, Craps bet scanner with EV traffic lights, Responsible gambling timer and journal.

App: https://optimalplay.pages.dev

If you have 5 minutes I'd really appreciate feedback on the tech side (or anything else): https://forms.gle/PwAz6rqG7xBCNz5t8

Happy to answer questions about the Cloudflare + next-on-pages setup, it was a bit of a journey.

reddit.com
u/Extension-Ad8058 — 7 days ago

Built a basic strategy advisor + trainer as a PWA — free, offline, no ads

Hey r/blackjack,

I've been working on a free tool for people learning basic strategy. It's a progressive web app (installable on Android, works offline) with:

- A basic strategy advisor that shows the correct play for any hand vs dealer upcard, with the EV of each option

- An interactive trainer that drills you on decisions and tracks your accuracy over time

- A Blackjack-specific explanation of expected value broken down into plain language, intermediate math, and full formula

No house rules tricks, no "advanced" strategy that requires counting — just solid basic strategy based on standard 6-deck S17 rules.

App: https://optimalplay.pages.dev

Would appreciate feedback from people who actually know the game: https://forms.gle/PwAz6rqG7xBCNz5t8

reddit.com
u/Extension-Ad8058 — 7 days ago

The May balance update is what people has been asking for months.

During the past few months people have complained about how easy it is to 3 star bases of same or even higher th.

But now that the Giant Arrow and the backpack have been nerfed (which took crucial part in most of the attacks) everyone is complaining.

Isn't this what everybody wanted? I believe this a step in the right direction for the stated reasons.

What does everybody think?

reddit.com
u/Extension-Ad8058 — 18 days ago