How to generate random number on GPU

Hi all,
how to generate random number on GPU, because I find generate a big rand tensor on CPU and then transform it into cuda tensor (a= torch.randn(1000,512,20,20); a.cuda())
is really CPU comsuming. Is any to generate it on GPU not CPU?Thank you advance!

The randn docs suggest that randn can take an out argument. You can do something like

shape = torch.Size((300, 300))
x = torch.cuda.FloatTensor(shape)
torch.randn(shape, out=x)

Yes, that what I am looking for, thank you a lot!

Doesn’t this still result in a data copy to the GPU? What if I want to generate directly on the GPU?

Did this speed up the generation process?