Skip to content

Durinx0/Monte-Carlo-Pi-Estimator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Monte Carlo Pi Estimator with Visualisation

This Python script estimates the value of π (pi) using a simple and intuitive Monte Carlo simulation, now enhanced with a matplotlib visualisation.


Idea Behind It

We randomly generate points inside a unit square (1×1) and count how many fall inside the quarter-circle inscribed in that square.
Using this ratio, we estimate π based on the formula:

π ≈ 4 × (points_in_circle / total_points)

This method is inspired by probability and geometry – and now also visualised!


â–¶How to Run

python estimate_pi.py

You will be prompted to enter a number n, which defines how many random points the simulation will use.

Example:

n = 10000
Pi ≈ 3.14124

A scatter plot will show:

  • Green dots = points inside the quarter circle
  • Red dots = points outside the circle
  • image

Requirements

  • Python 3.x
  • matplotlib (install with pip install matplotlib)

File Overview

File Description
estimate_pi.py Main script that performs the simulation and plot
README.md This documentation 📖

Author

Sebastian Strack
2025
Feel free to fork, modify, or visualise more!


Optional Ideas

  • Animate the points being drawn
  • Track Ï€ convergence as number of points increases
  • Compare multiple simulations

About

Short program to estimate pi, given that you have random (0, 1)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages