我需要一个包含基数nlittle的整数的列表,这些整数必须是随机的(valuemin,value),但是我在运行下面的代码时得到了大于population的错误样本
nlittle=random.randrange(5,15)
value=random.randint(1,100)
valuemin=int(valore*0.8)
minmoduniform=5*valoremin
maxmoduniform=20*valore
puniform=random.sample(xrange(valuemin,value), nlittle)
rouniform=random.sample(xrange(valuemin,value), nlittle)
如果nlittle(在我的代码中)大于xrange的差异,我如何解决这个问题并打印一个列表? 泰
//获取基数
我同意@Jasper。重新措辞你的问题。在
一个可能的解决方案是使用
//查看代码可能出错的原因。在
您的代码片段可能在多个实例中遇到问题。在
我们来接个案子吧。在
nlittle是一个介于5和15之间的随机整数。说是15岁 值介于0到100之间。假设它被分配了3。 希望,瓦莱敏不到三个说1。(我不能确定,因为我不知道瓦洛雷明)
您试图从一个包含2个对象的列表中获取15个对象的示例,该列表给了您错误。在
请参阅随机库的文档。那会更有帮助 https://docs.python.org/2/library/random.html
我正在添加一个摘录从网站为随机抽样(pop,k)在下面。在
这将在}之间选取
valuemin
和{nlittle
整数。在相关问题 更多 >
编程相关推荐