You can use the randn function to generate random numbers. n=300;
minval=0;
maxval=1000;
mu=50;
sd=50;
data=floor(mu+sd*randn(n,1));
invalid= data<minval | data>maxval;
while any(invalid)
data(invalid)=floor(mu+sd*randn(sum(invalid),1));
invalid= data<minval | data>maxval;
end
Best Answer