上QQ阅读APP看书,第一时间看更新
20. Monte Carlo π
A Monte Carlo algorithm uses randomness to approximate the solution to a problem. Often, using more random samples gives you a more accurate approximated solution or gives a greater probability that the solution is correct.
For this problem, use a Monte Carlo algorithm to approximate π. To do that, generate random points in the square (0 ≤ X, Y ≤ 1) and then see how many fall within a circle centered in that square.