I came across a question to implement an unbiased random function which outputs 0 or 1 using a biased output function which outputs 0 or 1 with probability P for outputting 1. And to predict how the runtime varies in accordance with P
I implemented it as follows
Random() {
i = BRand();
j = BRand();
if(j==0) j=1;
else j=0;
if(i==j)
Return i;
else
Random();
}
But I'm unable to figure out how the runtime would vary in terms of P.