随机概率

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import numpy as np
d={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
print(d)

ran=np.random.randint(0,10,1000000)
print(ran)

for i in range(10):
print(d[i])

for i in range(1000000):

if ran[i]==0:
d[0]=d[0]+1
elif ran[i]==1:
d[1]=d[1]+1
elif ran[i]==2:
d[2]=d[2]+1
elif ran[i]==3:
d[3]=d[3]+1
elif ran[i]==4:
d[4]=d[4]+1
elif ran[i]==5:
d[5]=d[5]+1
elif ran[i]==6:
d[6]=d[6]+1
elif ran[i]==7:
d[7]=d[7]+1
elif ran[i]==8:
d[8]=d[8]+1
elif ran[i]==9:
d[9]=d[9]+1
else:
print('kon')

for i in range(10):
print(d[i],d[i]/100)

posted on 2019-11-24 23:05  拓子  阅读(337)  评论(0编辑  收藏  举报

导航