Ed de Moel

Calculate π by throwing darts

This program throws darts randomly into the square shown. The value of π is approximated by counting the number of hits within the quarter circle versus the number of hits outside of it. Since the area of the quarter circle is ¼πr2 and the area of the square is r2, the value of π can be approximated as 4*within/total (where within is the number of hits within the quarter circle, and total is the total number of throws).

(Of course, this approximation says more about the quality of the random generator than about the value of π.)
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
 

 50 per second
 20 per second
 10 per second
 5 per second
 2 per second
 1 per second
 Stop