# How to sample from unknown distribution

Let's just assume on the picture we have a prob. distribution of aliens height on a Mars. We know for sure, the area below the curve is 1.

But I have a different question. How do we approach sampling from unique distributions as this is? Taking mean, variance, standard deviation out of it, etc, would not be really helpful, I guess, or it would be? Basically, I am just interested in how to sample from distributions, which are not well defined such as normal distribution etc.

You apply the mathematical inverse of the cumulative distribution function to numbers randomly sampled from a uniform distribution on the interval $$[0,1]$$.

Suppose for example you want to sample numbers from the exponential distribution which has a probability density function,

$$f_X(x) = \frac{1}{\tau} e^{-x/\tau}\qquad (0\leq x ),$$

the cumulative distribution function is defined as,

$$F(z) = P( X < x)$$ $$= \int_0^z f_X(x) dx$$ $$= \frac{1}{\tau} \int_0^z e^{-x/\tau} dx$$ $$= e^{-z/\tau} - 1$$

Now we have that,

$$F(z) = 1 - e^{-z/\tau},$$

the mathematical inverse of this function is,

$$F^{-1}(z) =-\tau \log(1-z).$$

======

Now we will apply the method I described at the beginning of this answer to get numbers sampled from the exponential distribution.

First I need a source of uniformly random numbers on the interval from $$[0,1]$$. I will use random.org to generate these numbers.

https://www.random.org/decimal-fractions/

======

I generated 100 random number sampled from the uniform distribution on $$[0,1]$$ using the random.org link above. The histrogram from these numbers follows.

Then I applied $$F^{-1}(z)$$ to each of these numbers (I chose $$\tau=1$$). The resulting list of numbers obtained from this process obeys an exponential distribution. Their histogram is shown below.

You can see that the histogram has changed to have a shape consistent with an exponential distribution.

• Spencer, could you please give me more details, perhaps a simple example. I have an intuition about it, but I am not really sure. Or perhaps guide me with technique, method I can google it. Thanks. Sep 28, 2019 at 16:09
• Sure I will try to flesh out the answer a bit. Sep 28, 2019 at 16:11
• You may also find a previous answer I provided here helpful. math.stackexchange.com/questions/2613604/… Sep 28, 2019 at 16:28
• Does this sufficiently answer your question? Sep 28, 2019 at 16:29
• Yes, this is very helpful. I appreciate it a lot. Sep 28, 2019 at 17:22