Home | Games | Awards | About | Learn | Blog | Press Kit | Contact | ||||
By: Matthew Doucette Last night, I wrote a quick program to estimate Pi via random numbers.
Algorithm: 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.
Results: 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%.
Downloads:
Speeds are measured by average after 1 minute of calculation, on my gaming laptop:
Optimizations:
Any more ideas? Let me know!
Video:
Inspiration: "Random Pi" was inspired by the following video by Physics Girl and Veritasium:
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 $180,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. |
Home | Games | Awards | About | Learn | Blog | Press Kit | Contact Email: Xona Games, Xona.com, Xonatech, Saw Tooth Distortion, Evolutionary Prototype (EP), Duality ZF, Decimation X, Decimation X2, Decimation X3, Decimation X3.5, Decimation X4, Score Rush, Score Rush 2, Score Rush (HTML5), Score Rush MP, and Score Rush Extended (Score Rush EX) trademarked and copyrighted by Xona Games Inc., Matthew Doucette, and/or Jason Doucette. © 2000..2005 Saw Tooth Distortion. © Xona.com. © 2008..2010 Xona Games (under Xona.com). © Xona Games Inc. We make Intense Retro video games. |