Suppose you have a unit square with a circle of unit diameter inscribed . You can compute a few digits of the transcendental number, pi, 3.1415926535897932384626433832795…, by using the algorithm described as follows. Let n be the number of darts to throw and h be the number of darts that land within the inscribed circle.
h = 0
for i = 1 to n do
Choose two random numbers x and y such that x and y are contained in the interval 0 to 1 inclusive that is x and y contained in [0, 1]
Let u = x – 1 / 2 and v = y – 1 / 2
if u * u + v * v <= 0.25 = 1 / 4 then h = h + 1
next i
pi = 4 * h / n
Below are the results of a C# Microsoft Visual Studio simulation project. In the first case we throw 100,000 darts and get two significant digits of pi and then we throw a 1,000,000 darts and five significant digits of pi are computed. Of course, in a previous entry by this author we can calculate hundreds or thousands of digits of pi in relatively little time:



