Search code examples
matlabnormal-distributionuniform-distribution

Why does the randn function return a number larger than 1?


I thought randn returns a random number which belongs to a normal distribution with mean 0 and standard deviation 1. Therefore, I expect to get a number in the range (0, 1). But what I get is a number not in the range (0,1).

What am I doing wrong?


Solution

  • You are thinking of a uniform distribution. A normal distribution can, in theory, have very big numbers, with very low probability.

    randn has a mean of 0 and standard deviation of 1. The normal distribution is the bell-curve / Gaussian shape, with the highest probability at the mean and probability falling off relative to the standard deviation.

    What you are looking for is rand, which "samples" from a uniform random distribution, which gives numbers bounded between 0 and 1 with even probability at all points.