I saw:

  
      stackoverflow.com
  
  
      
    
  

  How to get a uniform distribution in a range [r1,r2] in PyTorch? 82



  pytorch, uniform-distribution



  asked by
  
  
    Bishwajit Purkaystha
  
  on 12:05PM - 02 Jun 17 UTC


  
  
    
    
  
  


and thought that was a strange way to do it.
So there isn’t something default like torch.uniform?

their code:
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:

(r1 - r2) * torch.rand(a, b) + r2
Alternatively, you can simply use:

torch.FloatTensor(a, b).uniform_(r1, r2)