我想写一个模拟骰子掷100次的程序,但我必须如何做到这一点?这是代码:
import random
def roll() :
print('The computer will now simulate the roll of a dice 100 times')
number = random.randint(1,6)
print([number])
roll()
创建一个100卷的列表:
import random
print([random.randint(1,6) for _ in xrange(100)])
dansalmo的答案似乎不错,但如果您使用的是Numpy
您只需要使用numpy.random.randint(1,6,100)
,因为这将更有效,并且还将使用离散均匀分布来取出值