Bad PI Approximation

Actionscript:
  1. var inside:Number = 0
  2. var precision:Number = 1000000;
  3. for (var i:int = 0; i<precision; i++){
  4.        var xp:Number = 0.5 - Math.random();
  5.        var yp:Number = 0.5 - Math.random();
  6.        if (Math.sqrt(xp * xp + yp * yp) <0.5){
  7.                inside++;
  8.        }
  9. }
  10. trace(inside / precision * 4);
  11. // 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...

This entry was posted in Math and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted October 11, 2009 at 8:54 am | Permalink

    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 :(

  2. Posted October 11, 2009 at 9:23 am | Permalink

    Yeah its pretty funny/bad…. but still cool to think about :)

One Trackback

  1. By Twitted by Algorithmist on October 11, 2009 at 6:23 am

    [...] This post was Twitted by Algorithmist [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*