Monte Carlo Method
Estimate pi by essentially throwing darts - (pdf)
- Draw a unit square.
- Inscribe a circle inside the square.
- Throw a whole bunch of darts at the square, distributing them as randomly as possible.
- Count the number of dart holes inside the circle. Divide by the total number of dart holes. Now you have an estimate of the ratio of the areas of the circle and the square. Call this number C. Since you know the area of the square is 1, the area of the circle must be C. C is also equal to pi * r^2, where r is the radius of the inscribed circle (which is 0.5). Thus, C = pi * (0.5)^2 = pi/4. Pi is therefore approximately 4C.
see also
Written on June 6, 2018, Last update on September 11, 2022
math
algorithm