【发布时间】:2018-02-21 01:43:11
【问题描述】:
tmp = []
while len(tmp) == 0:
for i in range(0,385):
# Multiplying by 100 in order to remove the decimal point
if randint(0,10000) < chance*100:
tmp.append(i)
return tmp
这是我目前用来帮助解决问题的代码。输出将是这样的。
[34, 234, 243, 321]
我目前的解决方案效率很低。我试过这个:
sample(range(0,385), math.ceil(chance*3.85))
但它不会产生相同的效果。另外,如果你能告诉我这叫什么名字,那就太好了。
【问题讨论】:
标签: python arrays numpy random sublist