random计算pi值

import random
import time
start=time.perf_counter()
darts=30000000 #抛撒点总数
hits=0     #圆内点个数
for _ in range(darts):
    x,y=random.random(),random.random()
    dist=(x**2+y**2)**0.5
    if dist<=1:
        hits+=1
tm=time.perf_counter()-start       
print("Pi的近似值为{:.5f}.计算时间为{:.2f}".format(4*hits/darts,tm))