Calculates pi using a Monte Carlo method