MATLAB: Normally distributed demand data

codedatademandnormal distributionnormally random distributionrandom

Hi community,
I would like to make a normal random distribution for a demand set in Matlab with a range from [0 100]. However, I can not come up with a good working good yet. Does anyone have an idea how to do this?
Thankyou,

Best Answer

You can use the randn function to generate random numbers.
n=300;%number of cases
minval=0;%lowest allowed integer
maxval=1000;%highest allowed integer
mu=50;%median value of distribution
sd=50;%standard deviation of distribution
data=floor(mu+sd*randn(n,1));%round down to integers
invalid= data<minval | data>maxval;
while any(invalid)
%replace invalid values with newly generated values
%this will bias the distribution
data(invalid)=floor(mu+sd*randn(sum(invalid),1));
invalid= data<minval | data>maxval;
end