What you're given:
$p \in (0,1)$, but you don't know the value of $p$.
You have an algorithm $\mathcal{A}_p$ that returns $1$ with a probability of $p$ and $0$ with a probability of $(1-p)$. You can think of this as a biased coin throw. You may throw the coin as often as you want and the bias doesn't change.
What I've concluded:
You can get an algorithm $\mathcal{A}_\frac{1}{2}$ that returns 1 with a probability of $0.5$ and $0$ with a probability of $0.5$:
A_0.5() {
int x = 0, y = 0;
while (x == y) {
x = A_p();
y = A_p();
}
return x;
}
It is obvious that you can get any algorithm $\mathcal{A}_\frac{1}{2^n}$ by executing $\mathcal{A}_\frac{1}{2}$ $n$ times in a row.
The corner cases $\mathcal{A}_1$ and $\mathcal{A}_0$ are easy:
A_1() {
return 1;
}
A_0() {
return 0;
}
The question:
Can you get any algorithm $\mathcal{A}_q$ with $q \in \mathbb{Q} \cap [0,1]$?
Can you get any algorithm $\mathcal{A}_r$ with $r \in \mathbb{R} \cap [0,1]$?