繁体   English   中英

如何在python中生成具有特定概率的随机数?

[英]How to generate random numbers with specific probabilities in python?

例如,

尝试生成只有0 and 1的 1000 个随机数的列表。

0 has the prob of 40%

1 has the prob of 60%

谢谢!

我的概率 = []

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)

打印(我的问题)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM