posted by
mohit_at_codepad
on Apr 25
- Law of big number says, as NUM_ITER increases (approaches infinity), output number reaches pi.
- Radius must be a power of 2.
- Here I took a quarter circle of radius RADIUS centered around zero. and a square of side RADIUS bounding the quarter circle. Now I took NUM_ITER random points inside square. If the point is inside circle, I increase count by 2. If it is on the circle, increase the count by 1. The ratio of area of quarter circle and square is pi/4.
reply