MATLAB: Normal distribution for a given range of numbers.

normal distributionrandomrandom number generator

I have a range in which my parameter can vary for example, 0.38 to 0.5. I need to produce in between points such that the data will be normally distributed. I have thought of the followig way.
% code
xmin=0.38
xmax=0.5
n=20
x=xmin+randn(1,n)*(xmax-xmin);
But randn(1,n) gives me random numbers from more than 1 as well. Which does not serve the purpose of putting the range. Then my xmax becomes more than 0.5. How to achieve this for normal distribution and the given range? Thank you 🙂

Best Answer

Use rand, instead of randn:

 x=xmin+rand(1,n)*(xmax-xmin);