Emiel.s
Emiel.s

Reputation: 937

Python: how to simulate the roll of a dice 100 times

I want to write an program that simulates the roll of a dice 100 times, but how do i have to do that? This is the code:

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()

Upvotes: 1

Views: 13774

Answers (2)

Akash Purandare
Akash Purandare

Reputation: 65

The answer of dansalmo seems good, but if you're using Numpy

You just need to use numpy.random.randint(1,6,100) as that would be much more efficient and will also use discrete uniform distribution to take out the values

Upvotes: 1

dansalmo
dansalmo

Reputation: 11686

Creates a list of 100 rolls:

import random

print([random.randint(1,6) for _ in xrange(100)])

Upvotes: 2

Related Questions