Random Pi

Sunday, October 22, 2017
By: Matthew Doucette

Last night, I wrote a quick program to estimate Pi via random numbers.

Random Pi running up to 100,000,000,000 iterations.



The idea is to randomly choose (x,y) points within the unit cube (-1.0..1.0,-1.0..1.0) and measure the percentage of points lying inside the unit sphere. Using the area of a circule formula -- area = pi * radius^2 -- you can deduce the inside:total ratio multiplied by 4 is Pi.

This is known as the Monte Carlo method.



On my first run, after 114,880,000,000 random points, Pi was estimated to be 3.1415975457520893, which is off by 0.00000489216, or 0.00015572236%.

On a second run, using v2.0, after 5,144,300,000,000 random points, Pi was estimated to be 3.1415924060968452, which is off by 0.000000247492948, or 0.00000787794%.



Speeds are measured by average after 1 minute of calculation, on my gaming laptop:



Any more ideas? Let me know!



Random Pi v1.0 (PC) - Estimating Pi with Random Numbers



"Random Pi" was inspired by the following video by Physics Girl and Veritasium:

Calculating Pi with Darts


2017-NOV-06 UPDATE:

Check out Not-So-Random Pi.


Check out our other prototype work if you wish.

That is all.



About the Author: I am Matthew Doucette of Xona Games, an award-winning indie game studio that I founded with my twin brother. We make intensified arcade-style retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $190,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won game contests, and have held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions -- relating to the games we make. Read about our story, our awards, our games, and view our blog.