This is because if you use torch.Tensor(10).random_(-5, 5), this means take random numbers between the max of your datatype -5, and 5. This behavior is similar to python lists : you can do list[-5:5], meaning start 5 elements before the end, to the 5th element. I’m not sure why this is the default behavior, and it doesn’t seem to be documented.
For example, If you’re using int 32, this will select integers between 2^32 - 5, and 5.
You could use torch.rand or torch.randn and then scale / translate it by the factors you need
Exemple : torch.rand(10) * 5 : floats between 0 and 5 (uniform distribution)
torch.randn(10) * 5 : normal distribution centered in 0, multiplied by 5 (sigma = 5)
EDIT : I updated my answer with ClementPinard precisions for normal distributions