torch.Tensor.random_¶ Tensor.random_(from=0, to=None, *, generator=None) → Tensor¶ 用從離散均勻分佈 [from, to - 1] 中取樣得到的數字填充 self 張量。如果未指定,值通常僅受 self 張量的資料型別限制。然而,對於浮點型別,如果未指定,範圍將是 [0, 2^mantissa],以確保每個值都可表示。例如,torch.tensor(1, dtype=torch.double).random_() 將在 [0, 2^53] 範圍內均勻分佈。