The random number in the computer is not a real random number, but a random number generated by some algorithm.
Just use a fixed random number seed to generate a fixed sequence of random numbers
The example is as follows
import numpy as np
num = 0
while (num < 5):
np.random.seed(0)
print(np.random.rand(1,5)) # 得到一个范围从0到1的 1行5列的随机数
num += 1
print('-------------------------')
The results obtained are as follows
In fact, the random number seed can only be used once, and the next time you use it, you must re-declare the random number seed
import numpy as np
num = 0
while (num < 5):
np.random.seed(0)
print(np.random.rand(1,5)) # 得到一个范围从0到1的 1行5列的随机数
num += 1
print('-------------------------')
The result is as follows
You will find that only the first one is the same, so you must declare it again every time you use the random number seed