擅长:python、mysql、java
<pre><code>import random
N = 10**5 # number of trials (ie, number of points to sample)
R = 10**5 # circle radius
def in_sphere(x, y, z):
return x**2 + y**2 + z**2 < R**2
c = 0
for _ in range(N):
p = random.randint(0,R), random.randint(0,R), random.randint(0,R)
if in_sphere(*p):
c += 1
pi = 6 * c / N
print(pi)
</code></pre>