📅  最后修改于: 2023-12-03 15:18:02.960000             🧑  作者: Mango
NumPy is a popular Python library used for numerical computing. One of the many things NumPy offers us is the ability to generate random values. random.int is a NumPy method used to generate random integers.
numpy.random.int(low=0, high=None, size=None, dtype='l')
import numpy as np
random_int = np.random.int()
print(random_int)
Output:
-295036245
import numpy as np
random_int = np.random.int(low=1, high=10)
print(random_int)
Output:
6
import numpy as np
random_int_array = np.random.int(low=1, high=10, size=(2, 3))
print(random_int_array)
Output:
[[9 7 1]
[9 3 3]]
import numpy as np
random_int_array = np.random.int(low=1, high=10, dtype='uint16')
print(random_int_array)
Output:
3