3 ms·
Another Monte Carlo angle: import random n=1000000 print(4.*sum(random.random()**2 + random.random()**2 < 1 for i in range(n))/n) Both this version and
by schoen 6y ago
Another Monte Carlo angle:
import random
n=1000000
print(4.*sum(random.random()**2 + random.random()**2 < 1 for i in range(n))/n)
Both this version and the Buffon's Needle version are a lot less efficient than the version in this article, because the article's version is making educated guesses about where the boundary is, while the randomized versions are making uneducated guesses. :-)