Clear questions and runnable code get the best and fastest answer 

PerlMonks 
Re: Pi calculatorby thaigrrl (Monk) 
on Feb 15, 2001 at 23:19 UTC ( #58694=note: print w/replies, xml )  Need Help?? 
I found this to be very cool. I wrote a paper on AI and the Monte Carlo Method in college so I found it even more interesting. Not a very efficient method of calculating PI but really trivial because of the accuracy of PI as the cycles increase. Did you come up with this on your own? Is this based on the Buffon pin drop method, where he drops a pin of length X on a page of parallel lines? If so bravo I found it really entertaining :)
Also the use of srand and rand (forcing the random number to be less than 1 but greater than zero) is pretty sweet. I wouldn't have thought of that.
Buffon's Needle Experiment:
PI = ^{355}/_{113} = 3.1415929 UPDATE
New comment:
The problem here is not srand. Think of an x,y plane with a 1x1 square with its center located at (0,0). Inside this square is a circle with a radius of 1, also with its center at (0,0) what is happening in this algorithm is you are coming up with two random numbers but only couting your $yespi if (x^2 + y^2) <=1 . This could be any coordinate inside the square, therefore all of the points outside the circle but inside the square will not equal pi. But everything inside the circle will. You get a number close to PI more often than not because the area within the circle is greater than that outside of the circle but within the square. Does this make sense?
In Section
Craft

