Randomness has many uses in science, art, statistics, cryptography, gaming, gambling, and other fields.
All the functionality you need is contained in the random package, a sub-package of numpy.
# Import numpy as np import numpy as np # Set the seed np.random.seed(123) # Generate and print random float print(np.random.rand())
randint() is a function of the random package to generate integers randomly. It will generate random integers from num1 to num2 - 1 (not including num 2).
import numpy as np np.random.randint(num1, num2)
Example: Generates the integer 4, 5 or 6 randomly. 7 is not included.
# Import numpy and set seed import numpy as np np.random.seed(123) # Use randint() to simulate a dice print(np.random.randint(4,7))