random and np.random
def test_random():
import random
random.seed(1)
# [1,5]的一个随机整数, params: low (include), high (include)
print(random.randint(1, 5)) # 2
# [0,1)的一个随机数
print(random.random()) # 0.5692038748222122
import numpy as np
np.random.seed(1)
# [0,1)的一个随机数
print(np.random.random()) # 0.417022004702574
print(np.random.random(size=[3]))
"""
[7.20324493e-01 1.14374817e-04 3.02332573e-01]
"""
print(np.random.random(size=[2,3]))
"""
[[0.14675589 0.09233859 0.18626021]
[0.34556073 0.39676747 0.53881673]]
"""
# 随机整数
# np.random.randint区别于random.randint
# np.random.randint: low(include), high(exclude)
# random.randint: low(include), high(include)
print(np.random.randint(low=1, high=5, size=[2,4]))
"""
[[3 2 3 1]
[4 1 3 1]]
"""
return None