Skip to main content

MontyCarlo

A Monte Carlo simulator for the Monty Hall Problem

A.K.A.

"Two goats, one car"

This project simulates the classic Monty Hall problem and estimates the empirical win rates for staying vs switching. It adheres to the standard rules, and prints clean JSON for easy piping to other tools.

Rules

  1. The prize is hidden uniformly at random behind one of three doors.
  2. The contestant picks one door uniformly at random.
  3. The host opens one of the other two doors, and reveals a goat. The host always knows where the prize is, and never opens the contestant’s chosen door or the prize door.
  4. The contestant may stay with the original door or switch to the remaining closed door.

The MontyCarlo simulator runs a large number of independent trials conforming to these rules and reports the observed win rates for both strategies.

Requirements

  • Python >=3.10

Installation

git clone https://github.com/DJStompZone/MontyCarlo.git
cd MontyCarlo
pip install .

Or install directly with pip:

pip install two-goats-one-car

Project Layout

MontyCarlo/
├── LICENSE
├── pyproject.toml
├── README.md
└── two_goats_one_car/
    ├── __init__.py
    ├── __main__.py     # CLI entrypoint (python -m montycarlo)
    ├── monty.py        # Monty class & simulation logic
    └── results.py      # Dataclasses for trial results

Usage

Arguments

  • -n, --trials — Number of trials to run (default: 100000).
  • -s, --seed — PRNG seed for reproducibility (default: none).

Reproducibility

  • Set --seed to fix the RNG stream.
  • Larger -n reduces sampling noise
  • Expect absolute error to shrink roughly with $(O(1/\sqrt{n}))$.

Example

# Run 1,000,000 trials with a fixed seed:
montycarlo -n 1000000 -s 69420

Example Output

{
  // Number of trials run
  "trials": 1000000,

  // Empirical probability of winning by staying
  "stay_win_rate": 0.333021,

  // Empirical probability of winning by switching
  "switch_win_rate": 0.666979,

  // Difference between switch and stay win rates
  "delta": 0.333958
}

License

MIT. See the LICENSE file for details.

Disclaimer

Don't come crying to me if you try this on a real game show and still pick the goat. :D

Metadata

Release files for two-goats-one-car 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for two-goats-one-car 1.0.2
File Size Uploaded
two_goats_one_car-1.0.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for two-goats-one-car 1.0.2
File Interpreter ABI Platform
two_goats_one_car-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / two_goats_one_car-1.0.2.tar.gz

Download URL two_goats_one_car-1.0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3c51ea05d0a6f1b51fd6831495135a65e9216f250eb232cc11a03e3cd2ec1f7d
BLAKE2b-256 checksum
How to use checksums
2efc384f3c93e1734e78ace07167ec6b62bf77081314a85eaeb19156afedc6eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.11 Windows/11

Release files / two_goats_one_car-1.0.2-py3-none-any.whl

Download URL two_goats_one_car-1.0.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4fa3da0dc99bc80c183f3d5ce8d78140959c663e75c7dc70624ff7f56f71028
BLAKE2b-256 checksum
How to use checksums
6393b2932ce5554d992bfa2e970c4fe1411bd9c89291b499e91b001317688ae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.11 Windows/11

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page