[英]How to generate random numbers with specific probabilities in python?
For example,例如,
Try to generate a list of 1000 random numbers with only 0 and 1
.尝试生成只有0 and 1
的 1000 个随机数的列表。
st圣
0 has the prob of 40%
1 has the prob of 60%
thanks!谢谢!
myProb = []我的概率 = []
for i in range(1000):
#creates one number out of 0 or 1 with prob p 0.4 for 0 and 0.6 for 1
test = numpy.random.choice(numpy.arange(0, 2), p=[0.4, 0.6])
myProb.append(test)
print(myProb)打印(我的问题)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.