接近0.3
$ cat monte.py
import random,math
density=int(1e6)
x = [random.uniform(0,1)*7*math.pi for _ in range(density)]
y = [random.uniform(0,1) for _ in range(density)]
i = [math.sin(xx)*math.cos(xx) > yy for (xx,yy) in zip(x,y)]
print sum(i)/(float(density)*10.0)*7*math.pi
$ python monte.py
0.350184850795
我正试图改写如下,但出于某种原因, code法甚至没有结束。
x = rand(1, 1000000)*7pi;
y = rand(1, 1000000);
i = sin(x).* cos(x) >y;
Area3 = (sum(i) / 10000000)*7pi;