Search code examples
algorithmstatisticsgaussiannormal-distributionpoisson

Generating a gaussian distribution with only positive numbers


Is there any way to randomly generate a set of positive numbers such that they have a desired mean and standard deviation?

I have an algorithm to generate numbers with a gaussian distribution, but I don't know how to deal with negative numbers in a way the preserves the mean and standard deviation.
It looks like a poisson distribution might be a good approximation, but it takes only a mean.

EDIT: There's been some confusion in the responses so I'll try to clarify.

I have a set of numbers that give me a mean and a standard deviation. I would like to generate an equally sized set of numbers with an equivalent mean and standard deviation. Normally, I would use a gaussian distribution to do this, however in this case I have an additional constraint that all values must be greater than zero.

The algorithm I'm looking for doesn't need to be gaussian-based (judging by the comments so far, it probably shouldn't be) and doesn't need to be perfect. It doesn't matter if the resulting number set has a slightly different mean/standard deviation -- I just want something that will usually be in the ballpark.


Solution

  • You may be looking for log-normal distribution, as David Norman suggested, or maybe exponential, binomial, or some other distribution. If you have an algorithm to generate one distribution, it is probably not good for generating numbers conforming to another distribution. But only you know how your numbers are really distributed.

    With normal distribution, the random variable's range is from negative infinity to positive infinity, so if you're looking for positive numbers only, then it is not Gaussian.

    Different distributions also have unique properties, for example, with Poisson distribution, the standard deviations is always equal to the mean. (That's why your library function doesn't ask from the standard deviation parameter, only the mean).

    In the worst case, you could generate a random real number between 0 and 1 and compute the probability density function on your own. (Depending on the distribution, this may be much easier said than done).