-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathroll-the-dice.py
More file actions
28 lines (22 loc) · 900 Bytes
/
roll-the-dice.py
File metadata and controls
28 lines (22 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
Roll the dice
100xp
In the previous exercise, you used rand(), that generates a random float between 0 and 1.
As Filip explained in the video you can just as well use randint(), also a function of the
random package, to generate integers randomly. The following call generates the integer
4, 5, 6 or 7 randomly. 8 is not included.
import numpy as np
np.random.randint(4, 8)
Numpy has already been imported as np and a seed has been set. Can you roll some dice?
Instructions
-Use randint() with the appropriate arguments to randomly generate the integer 1, 2, 3, 4, 5 or 6.
This simulates a dice. Print it out.
-Repeat the outcome to see if the second throw is different. Again, print out the result.
'''
# Import numpy and set seed
import numpy as np
np.random.seed(123)
# Use randint() to simulate a dice
print(np.random.randint(1, 7))
# Use randint() again
print(np.random.randint(1, 7))