Monte Carlo π

by David Reed, for A Balanced Introduction to Computer Science, 3rd ed.

This Web page performs two different Monte Carlo simulations that can be used to approximate the value of π.

Random darts: Consider throwing darts at a square dart board that has a circle inscribed in it. If the darts are completly random (i.e., equally likely to land anywhere in the square), then the ratio (darts inside the inscribed circle)/(total darts in the square) is an approximation of (area of circle)/(area of square) = π*radius2/(2*radius)2 = π/4. Therefore, π ≈ 4*(darts in circle)/(total darts in square).

Random needles: Consider dropping needles on a table top that has vertical lines drawn on it, where the distance between the lines is twice the length of the needles. If the needles are dropped randomly (i.e., equally likely to land anywhere on the table, at any angle), then π ≈ (total needles on table) / (points crossing a line). This result was first proven by French mathematician Georges-Louis Leclerc, Comte de Buffon.


Your browser does not support the HTML5 canvas tag. Number of darts to generate:    




Number inside the circle: 0
Total number of darts: 0


 
 
Your browser does not support the HTML5 canvas tag. Number of needles to generate:    




Number crossing a line: 0
Total number of needles: 0