Solving Pi

bjchrist at convex.UUCP bjchrist at convex.UUCP
Tue Aug 20 04:51:00 AEST 1985


As an aside: If you know PI you can check a random number generator by the
	accuracy with which it calculates pi by the following means:

	|a square with coordinates: (0,0) (1,0) (1,1) (0,1) has an area
	|of one (1)
	|
given:	|a circle with radius 1 has as its area PI. Plot the circle on graph
	|paper with is center at (0,0). The area of the circle falling
	|in quadrant 1 is PI/4. So the ratio of points within the square's
	|area AND within the circle's area is PI/4.

	write a program to generate two random numbers 0<= x <= 1.0
	keep count of the number of times sqrt(x**2 + y**2) <=1.0

	the ratio of the hits (sqrt(x^2 + y^2) <= 1.0) to misses will give
	you PI/4. The rate of convergence is horrible but it's interesting
	to compare random number generators and their accuracy. If a
	REAL *random* number generator is used. After an infinite number
	of shots, you will really have PI. Assuming you have an infinitly
	accurate calculator.



More information about the Comp.sources.unix mailing list