Actionscript:
-
var inside:Number = 0
-
var precision:Number = 1000000;
-
for (var i:int = 0; i<precision; i++){
-
var xp:Number = 0.5 - Math.random();
-
var yp:Number = 0.5 - Math.random();
-
if (Math.sqrt(xp * xp + yp * yp) <0.5){
-
inside++;
-
}
-
}
-
trace(inside / precision * 4);
-
// outputs : 3.143304
Someone described this bad method of a PI approximation to me the other day... figured I'd try it out... pretty funny. I always liked 22/7... but this one is definitely funnier...
2 Comments
Yes, this method is unbelievably bad, it’s like it never ever converges to pi… Go here, wait as long as you want, and you still can’t get 0.01% precision
Yeah its pretty funny/bad…. but still cool to think about
One Trackback
[...] This post was Twitted by Algorithmist [...]