top of page

Using Technology to Estimate Pi with Random Numbers and Geometry

By Zach Spangler '22

Using Technology to Estimate Pi with Random Numbers and Geometry

There are many ways to estimate pi, from the sum of the inverse squares (something actually related to the zeta function) 1 to the simple physical experiment of running a piece of string along a circle and comparing it to the radius. However, one of the most interesting ways to calculate pi is by using random numbers.


The strategy is to pick two random real numbers between -1 and 1. From there, take the square root of the sum of the squares of the two. If this is less than 1, a counter is incremented. After a large number of runs, this counter is divided by the total number of runs. This converges to π/4. 


With the first five powers of 10, a simulation of this provided the following values: 2.8, 3.28, 3.132, 3.1144, 3.14688.


Why does this happen? It is because the range of possible values for the two numbers forms a square in ℝ2. The boundary for incrementing the counter is then a unit circle. Hence, the ratio of these numbers, for both random numbers chosen in a linear distribution, is the area of the circle divided by the area of the square, which is π/4. The following graph, drawn by code available at the end of this article, demonstrates this:


The blue circle is the boundary for the counter, and the black dots are the random points chosen.


1: https://doi.org/2319041

Code:

https://colab.research.google.com/drive/1fU5tgOVwMHwC_wmIvWY5iJ9ob4uhjUYo?usp=sharing

bottom of page