Suppose I would like to generate random numbers in a way that they satisfy some probability distribution with a mean $\mu$ and standard deviation $\sigma$, what is a formula for that?

Thank you.

  • $\begingroup$ Like a normal distribution? $\endgroup$ – Raskolnikov Jun 27 '12 at 22:02
  • 1
    $\begingroup$ once you can generate a uniform distribution you can just plug that into the function of whatever other distribution you want. Also note that 'probability distribution' could be a bunch of things (normal, uniform, exponential, etc). This isn't nearly specific enough. $\endgroup$ – Robert Mastragostino Jun 27 '12 at 22:09
  • $\begingroup$ @Raskolnikov: Yes, but I am wondering if there is a formula in general, so for any distribution say $\rho$. $\endgroup$ – yaz Jun 27 '12 at 22:14
  • $\begingroup$ @RobertMastragostino: How do you plug that into another distribution? I suppose we can use the normal distribution as an example to begin with, I guess the "plugging in" will be similar for other distributions. $\endgroup$ – yaz Jun 27 '12 at 22:16

The following strategy is very general. Let $F(x)$ be the cumulative distribution of $X$. Assume $F$ is invertible and $U$ is a uniform random variable in $(0,1)$. Then $F^{-1}(U)$ is distributed as $X$. The proof is very simple:

$$P(F^{-1}(U) \leq x) = P(F(F^{-1}(U)) \leq F(x)) = P(U \leq F(x)) = F(x)$$

For example, if $X$ follows an exponential distribution with parameter $\lambda$,

$$F(x) = 1-e^{-\lambda x}$$

$$x = -\frac{\log(1-F(x))}{\lambda}$$

Hence, $-\frac{\log(1-U)}{\lambda}$ follows an exponential distribution with parameter $\lambda$.


As far as I know, there is no way to generate "true" uniform random numbers using a formula. All formulas are deterministic. Most cryptographically-secure methods of generating random numbers require the use of specialized hardware. There are circuits to perform random number generation. Once you have a uniform distribution of numbers you can then use something such as the Box-Muller transform to get normally distributed random numbers. Or maybe the Ziggurat algorithm is what you are looking for?

Perhaps use an algorithm that can generate random numbers with mean $\mu$ and standard deviation $\sigma$ for any type of distribution. The algorithm is not completely "random", and it is not a formula, but it is a process that can give fairly good random numbers.

For a ready-made solution, Matlab normrnd might be what you are looking for, if you want normally distributed random numbers.

If you want to generate sample numbers at random from any probability distribution, then the inverse transform sampling method might be the way to go.

In short, generate uniform random numbers, and then use other methods (Random number generation) to get the random numbers from the distribution that you want.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.