# 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$$.
A random sample $$X$$ of just one real number from a $$\text{Uniform}(0,1)$$ distribution is equivalent to sampling an infinite sequence of i.i.d. $$\text{Bernoulli}(1/2)$$ random variables $$X_1,X_2,...$$ as the binary digits of $$X=(0.X_1X_2X_3...)_2.$$ (See Represent a Uniform[0,1] random variable as a sum of independent Bernoulli(1/2) random variables.)