user2032717 user2032717 - 1 year ago 106
R Question

Generate positive random numbers with fixed mean and SD

How can I generate a positive random number list with specified mean and SD?
I know how to do it with rnorm in R but it is not positive since it sampled from a normal distribution, if I'm right.

My preferred language is matlab but a script in R is Ok too.

Answer Source

It really depends on the underlying distribution.

With R = normrnd(mu,sigma) you can generate normal distributed random numbers with specified mean and standard deviation.

R = lognrnd(mu,sigma) generates lognormal distributed random numbers.

You can also take a look at this where you can specify the distribution.

Just make sure that you check if it really is positive, e.g.

mu = 10;
sigma = 1;
R = normrnd(mu,sigma,1,500); 
   %R(R<=0) = resample
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download