Why randn doesn't always have a mean of 0 and variance of 1?
For the PyTorch.randn() method the documentation says:


  Returns a tensor filled with random numbers from a normal distribution
  with mean 0 and variance 1 (also called the standard normal
  distribution).


So here is an example tensor:

x = torch.randn(4,3)
tensor([[-0.6569, -0.7337, -0.0028],
        [-0.3938,  0.3223,  0.0497],
        [ 0.0129, -2.7546, -2.2488],
        [ 1.6754, -0.1497,  1.8202]])


When I print the mean:

x.mean()
tensor(-0.2550)


When I print the standard deviation:

x.std()
tensor(1.3225)


So why isn't the mean 0 and the standard deviation 1?

Bonus question: How do I generate a random tensor that always has a mean of 0?

It would be a big coincidence that a finite sample of the distribution has exactly the same mean and exactly the same standard deviation. It is to be expected that the more numbers you generate, the closer the mean and deviation of the sample approaches the "true" mean and deviation of the distribution.
