Imagine a circular dartboard of radius 1 foot mounted on a square backdrop of side 2 feet. Now suppose darts are thrown. Of the darts that land within the square, some will land inside the circle of the dartboard (hits) and others will lie outside the circle but inside the square (misses).
Imagine the dartboard centered on a cartesian grid with its center at (0,0). Select two floating point numbers x and y both in the range from -1.0 to 1.0. are the coordinates of a dart randomly thrown that lands within the square. Sometimes, the dart will also be within the circle.
You can write a program to simulate throwing darts. Furthermore, it can count how many darts land within the dartboard. If you throw enough darts, the ratio of will begin to approximate the probability that a random dart will land inside the circular dartboard.
And we know that the area of the square is 4 square feet.
Now you're ready to estimate the value of PI using simulation.
> simpi 78 hits in 100 throws for PI value 3.120000 Hit q to quit, ENTER to continue > 155 hits in 200 throws for PI value 3.100000 Hit q to quit, ENTER to continue > 231 hits in 300 throws for PI value 3.080000 Hit q to quit, ENTER to continue > 310 hits in 400 throws for PI value 3.100000 Hit q to quit, ENTER to continue > 391 hits in 500 throws for PI value 3.128000 Hit q to quit, ENTER to continue > q