NumPy random.randint - How to get random integers | Python

NumPy has random module and it has randint function that returns random integers as an array.

import numpy

a1 = numpy.random.randint(low=1, high=5, size=[3])
a2 = numpy.random.randint(low=4, high=24, size=[3])
a3 = numpy.random.randint(low=-9, high=-4, size=[5])

print(a1)  # [4 2 3]
print(a2)  # [14 11 22]
print(a3)  # [-9 -5 -8 -6 -5]

low and high argument mean the lowest and largest integer, respectively, shown in the array. size is the size of array.

import numpy

a1 = numpy.random.randint(low=1, high=5, size=[2, 3])
a2 = numpy.random.randint(low=4, high=24, size=[4, 2])
a3 = numpy.random.randint(low=-9, high=-4, size=[1, 5])

print(a1)
# [[2 4 1]
#  [1 4 1]]

print(a2)
# [[22 15]
#  [ 4 16]
#  [ 7 21]
#  [ 7 12]]

print(a3)  # [[-6 -7 -8 -9 -5]]

NumPy Array

NumPy Tutorial