xxxxxxxxxx
import numpy as np
# Generate a single random number between 0 and 1
random_number = np.random.random()
print(random_number)
# Generate an array of 5 random numbers between 0 and 1
random_array = np.random.random(5)
print(random_array)
xxxxxxxxxx
np.random.randint(2, size=10) # Creates binary sample of size 10
np.random.randint(5, size=10) # Creates sample with 0-4 as values of size 10
np.random.randint(5, size=(2, 4))
xxxxxxxxxx
import numpy as np
np.random.seed(123)
print(np.random.randint(1,7)) # Random integer between 1 and 6
print(np.random.rand()) # Random float
np.random.random((2, 4)) # Matrix of 2 rows and 4 cols with random values
xxxxxxxxxx
import numpy as np
n = 2
m = 3
print(np.random.randn(n, m))
# prints random matrix with n rows and m columns
# example:
# array([[ 1.01267696, -1.85632995, 0.23078345],
# [ 0.34365521, -1.27063438, 2.90131288]])
xxxxxxxxxx
from numpy import random
n = random.randint(lowerbound(inclusive), higherbound(exclusive))