A Python module for simulating the probability of drawing specific combinations of colored balls from a hat.
Uses Monte‑Carlo simulation to estimate probabilities.
- 🎩 Hat class for creating bags of colored balls
- 🔀 Random drawing without replacement
- 📊 Monte‑Carlo probability estimation (
experiment) - 🧪 Fully customizable simulations
- 🖥️ Command Line Interface (
probability-calculator) - 🧾 Detailed documentation (MkDocs Material)
- ✔️ Fully tested and linted (pytest, flake8, black)
Clone and install:
git clone https://github.com/TheComputationalCore/Probability-Calculator.git
cd Probability-Calculator
pip install .from probability_calculator import Hat
hat = Hat(red=3, blue=2, green=6)
print(hat.contents)drawn = hat.draw(4)
print(drawn)from probability_calculator import experiment
prob = experiment(
hat,
expected_balls={"red": 2, "green": 1},
num_balls_drawn=5,
num_experiments=2000
)
print(prob)Run directly from the terminal:
probability-calculator --hat red=3 blue=2 green=6 --expect red=2 green=1 --draw 5 --experiments 2000Output example:
Estimated Probability: 0.2385
Full documentation is available at:
➡️ https://thecomputationalcore.github.io/Probability-Calculator
Includes:
- Usage Guide
- API Reference
- CLI Guide
- Examples
- Contribution Guide
pytest -qThe repo uses:
- Black — code formatter
- Flake8 — linter
- pytest — tests
GitHub Actions automatically run:
- Lint checks
- Tests
- Docs deployment
Contributions are welcome!
Please read: CONTRIBUTING.md
See: SECURITY.md
Released under the MIT License.