Background

Take a square. Draw a circle in it so that the circle is completely contained in it and the square's side length is 2*r where r is the radius of the circle. The square's area is 4*r^2 and the circle's area is pi*r^2.



Now...randomly drop items into the square. The % of items that land inside the circle will be the same value as the circle's area divided by the square's area if you drop an infinite number of items, and the more items you drop, the closer the value will be. Given that the ratio of the areas is pi/4, the % of items that land inside the circle will approach the value of pi/4. Multiply that by 4, and you get a value for pi.





Simulations

First, I wanted to show this somehow. I settled on simulating a progressively larger number of tosses and plotting the results. The gif below shows the first quadrant of a circle of radius 1 inside a square of side length 2 with more and more dots being generated. The error at the top is equal to 4*(% in circle/pi) - 1. That's another way of writing the error in the estimation of pi.









A more interesting question is...how repeatable are these results? To find that, I ran the simulation 5000 times and tracked the error in each simulation after 100, 1000, 10000, and 100000 trials. The histograms showing the distribution of those errors is below:







