Python自帶的random庫


例如:
Python產生一個數值范圍內的不重復的隨機數,可以使用random模塊中的random.sample函數。例如從0~99中,隨機取10個不重復的數: random.sample(range(100), 10)
numpy的random庫

torch的隨機函數
torch.rand(*sizes) ,size可以是列表、元組或直接寫數字
Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)

torch.randn(*sizes) ,size可以是列表、元組或直接寫數字
Returns a tensor filled with random numbers from a normal distribution with mean `0` and variance `1`

torch.randint(low, high, size),size是元組形式
Returns a tensor filled with random integers generated uniformly on the interval [low, high)

torch.randperm():返回一個0到n-1的數組。
random_():

返回的是恰好為整數的浮點型數字,例如:

