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

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