GitHub Logo

Monte Carlo Pi

Approximate π\pi using the Monte Carlo method

1. Enter the number of points to generate using the input field.

2. (optional) Select the simulation mode.

3. Click the Start button to start the simulation.

The Monte Carlo method is a statistical method that uses random sampling to estimate numerical results.

In this simulation, a circle is inscribed in a quadrant. The ratio between the area of the circle and the area of the square isπr2(2r)2=π4\frac{\pi r^2}{(2r)^2} = \frac{\pi}{4}This means we can approximate pi by generating random points in the quadrant and calculating the ratio of points inside the circle to the total number of points.π4rn\frac{\pi}{4} \approx \frac{r}{n}r=points inside circler = \text{points inside circle}n=total pointsn = \text{total points}