A command-line Python tool for analysing historical lottery draw data and simulating drawings against your own number picks — with memory-efficient incremental statistics, live API data, and save/resume support.
Supports Mega Millions, Powerball, and any custom lottery configuration.
- Historical analysis — fetches real draw history from the NY Open Data API and caches it locally; displays hot/cold numbers, positional frequencies, and theoretical prize odds
- Live simulation — runs continuous random drawings at any speed, printing output only on noteworthy matches (≥2 white balls or the bonus ball)
- Multiple picks — simulate several ticket picks simultaneously against every draw
- Prize tier tracking — counts how many times each prize tier is hit across the whole session
- Memory-efficient — accumulates frequency counters incrementally; RAM usage stays flat regardless of how many draws are simulated
- Save & resume — save state mid-simulation with
s, reload withr, or clean up saves from the prompt - Cross-platform — Linux, macOS, and Windows; Unix-only terminal features are guarded appropriately
- Graceful degradation — falls back to built-in reference statistics if the API is unavailable; preserves partial fetches on network errors
- Python 3.8 or later
requestslibrary
pip install requestsNo other third-party dependencies.
# Clone the repo
git clone https://github.com/your-username/safeTcheck-android.git
cd lottery-analysis-sim
# Install the one dependency
pip install requests
# Run
python3 lotto_simulator_20260405e.pyOn Windows:
python lotto_simulator_20260405e.pySelect lottery:
(1) Mega Millions
(2) Powerball
(3) Custom lottery
Choice (1/2/3):
Choosing (3) prompts for pool sizes and draw counts, letting you model any numeric lottery format.
| Option | Description |
|---|---|
| 1 | Historical analysis (Mega Millions / Powerball) |
| 2 | Run a simulation |
| 3 | Force-refresh historical data from the API |
'u' user pick, 'q' quick pick, 'd' done/start:
Enter as many picks as you like before starting. Any unrecognised input prints a prompt reminder rather than silently falling through.
| Key | Action |
|---|---|
q |
Stop |
s |
Save state and continue |
r |
Reload a saved state and resume |
Enter delay between draws in seconds (0 = fastest, default 0.015):
At delay=0 the simulation runs at full CPU speed — millions of draws per minute — with no memory growth.
The simulation prints a line only when a pick achieves a result worth noting:
Draw 84213: White [7, 21, 28, 42, 66], Red 5
Pick 1: 3 white, 0 red (Prize: $10)
Draw 201847: White [3, 14, 28, 42, 66], Red 11
Pick 1: 4 white, 1 red (Prize: $200)
At the end of a session a full statistical report is printed — most common balls by position, hot/cold numbers, theoretical odds, and a tier hit summary:
Tier Hit Counts in Simulation:
5+1 (Grand Prize): 0 times
4+1 ($10,000): 1 times
3+1 ($200): 12 times
3+0 ($10): 47 times
2+1 ($10): 89 times
1+1 ($4): 312 times
0+1 ($2): 401 times
State is saved as timestamped JSON files (lotto_sim_save_YYYYMMDDHHMMSS.json) in the working directory. They store counters rather than raw draw lists, so they stay small (a few KB) regardless of session length.
Old-format saves from earlier versions (which stored raw draw lists) are automatically detected and migrated on load.
Historical draw data is cached in lottery_cache/ after the first fetch:
lottery_cache/
mega_millions_historical.json
powerball_historical.json
Data source: NY Open Data — Lottery
.
├── lotto_simulator_20260405e.py # Main script (v22)
├── lottery_cache/ # Auto-created; holds cached API data
│ ├── mega_millions_historical.json
│ └── powerball_historical.json
├── lotto_sim_save_*.json # Save files created during simulation
└── README.md
Mega Millions
| Match | Prize |
|---|---|
| 5 white + Mega Ball | Jackpot |
| 5 white | $1,000,000 |
| 4 white + Mega Ball | $10,000 |
| 4 white | $500 |
| 3 white + Mega Ball | $200 |
| 3 white | $10 |
| 2 white + Mega Ball | $10 |
| 1 white + Mega Ball | $4 |
| Mega Ball only | $2 |
Powerball
| Match | Prize |
|---|---|
| 5 white + Powerball | Jackpot |
| 5 white | $1,000,000 |
| 4 white + Powerball | $50,000 |
| 4 white | $100 |
| 3 white + Powerball | $100 |
| 3 white | $7 |
| 2 white + Powerball | $7 |
| 1 white + Powerball | $4 |
| Powerball only | $4 |
- This tool is for entertainment and analysis purposes only. Past draw frequencies do not influence future results — all lottery draws are statistically independent.
- Historical data availability depends on the NY Open Data API. The tool falls back to built-in reference statistics if the API is unreachable.
- The simulation uses Python's
random.sampleseeded from the OS entropy source — it is not cryptographically secure, but is statistically appropriate for this purpose.
MIT — see LICENSE for details.