I want to get a 2-D torch.Tensor with size [a,b] filled with values from a uniform distribution (in range [r1,r2]) in PyTorch. Answer If U is a random variable uniformly distributed on [0, 1], then (r1 – r2) * U + r2 is uniformly distributed on [r1, r2]. Thus, you just need: Alternatively, you can simply use: To fully explain