# Given a function that generates random numbers with uniform distribution over (0, 1) find a function to generate numbers with Bernoulli distribution.

If we have a continuous random variable $$X$$ with uniform distribution over $$(1, 0)$$ we can find functions that generate numbers with other distributions using this random variable.

For example if we want to generate numbers with exponential distribution which has the p.d.f $$\lambda e^{-\lambda x}$$ first we find the inverse of its p.d.f and give the random numbers generated by our uniform R.V. to that inverse function.

But some distributions such as Bernoulli distribution do not have monotone p.d.f and thus we cannot find an inverse function of their p.d.f.

My question is that how to find the desired function— i.e., the function that generates numbers with this new distribution— in this situations?

Edit:

I made a mistake using p.d.f instead of CDF. So all p.d.f.s used above should be replaced by CDF.

## 1 Answer

First and foremost, you are confusing PDFs/PMFs with CDFs. We invert CDFs (not PDFs/PMFs) to perform inverse sampling:

Lemma (Inverse sampling; weak version). Let $$Y\sim U[0,1]$$ and $$F$$ be an invertible CDF. Then, the random variable $$X \equiv F^{-1}(Y)$$ has CDF equal to $$F$$.

However, CDFs are not always invertible! (e.g., Bernoulli distribution) Fortunately, there is a stronger result:

Lemma (Inverse sampling; strong version). Let $$Y\sim U[0,1]$$ and $$F$$ be any CDF. Then, the random variable $$X\equiv\inf_{x}\{ x\colon F(x)\geq Y\}$$ has CDF equal to $$F$$.

• Thanks for your good answer. – AK 12 Mar 27 at 0:50