Generating random numbers

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.

-
Like a normal distribution? –  Raskolnikov Jun 27 '12 at 22:02
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. –  Robert Mastragostino Jun 27 '12 at 22:09
@Raskolnikov: Yes, but I am wondering if there is a formula in general, so for any distribution say $\rho$. –  yaz Jun 27 '12 at 22:14
@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. –  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$.

-
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.