generating random variable Suppose we have a coin that the probability of coming head is $p$. How can we generate a Bernoulli Random variable such a $X$ that the probability of both $0$ and $1$ is $\frac{1}{2}$, using this coin?

Just to expand lulu's answer.
Let's toss in group of two and record the outcome of the first appearance of two unequal dices, like $HT$ or $TH$. Let's suppose $p$ is the probability of getting heads and $q=1-p$. We introduce two random variables:

*

*$Z \in \{0,1\}$ be equal to $0$ if $HT$ comes first and $1$ if $TH$ comes first.

*Let us also introduce $N$ as the first time one of these double tosses comes with unequal outcomes.

Than:
$P(Z=0)=\sum_{n\ge1} P(Z=0, N=n)=\sum_{n\ge1} (p^2+q^2)^{n-1}pq=1/2$
And of course $P(Z=1)=1/2$
So we built indeed an even random variable from a biased dice, which is nice.
We can also avoid doing the summation if we believe in symmetry and normalization of course :) .
