Monte Carlo Method to Approximate Pi

The Method can be used to compute Pi by simulating the tossing of darts at circular dart board mounted on a square: If the darts are equally likely to hit any point in the square, then the proportion that hit inside the circle will approximate the ratio of the area of the circle to that of the square. If the square has sides of length 2.0, then that ratio is (pi*r**2)/(s**2) = (pi*1**2)/(2.0**2)=pi/4, so 4 times that ratio will approximate pi.

It is easier to use the quarter circle of radius 1 that lies in the first quadrant.This way, the randomly selected coordinates will all be in the range 0 and 1. The area of the square is 1**2 = 1 and the area of the quarter circle is pi*1**2/4=pi/4, so the ratio still pi/4.

This JavaScript program computes the pi using the facts given above for different number of tosses.


     Enter # of Tosses  :    
     Calculated Pi      : 
     Exact Value of Pi  : 
     Error (E-C)        : 
     Percentage Error % :