torch.rand outputs a tensor fill out with random numbers within [0,1). You can use that and convert it to the range [l,r) using a formula like l + torch.rand() * (r - l) and then converting them to integers as usual.
2 Likes