# Random number stream

We can create a random number generator/ stream in numpy
https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.RandomState.html
also in matlab
https://www.mathworks.com/help/matlab/ref/randstream.html

I was wondering if there is any function in Pytorch can do this

I mean there is the torch.randn and torch.randint. Hope that works for you. But could also create it in numpy and then convert it to a tensor with torch.tensor()

thanks. but that is no random stream

I’m not sure, if you’re looking the the generator, but maybe this post might help.

Yeah, unfortunately there is no implementation in PyTorch for that – the random seeds are all global. One solution though as others suggested:

is just to sample via NumPy and then convert to tensors … until there’s maybe a PyTorch implementation one day …

EDIT: just following the link on the answer above, it does seem that you can manually set the seed for the torch.Generator. That should then be equivalent and probably what you were looking for:

``````gen1 = torch.Generator()

gen1 = gen1.manual_seed(1)
torch.rand(5, generator=gen1)
``````