Unfair coin vs Random algorithm

128 Views Asked by At

I had bought an unfair coin. The probability of getting a tail is 75% P(T) = 3/4 and the probability of getting a head is 25% P(H) = 1/4

I decided to do the following experiment: I programmed a computer to generate a random boolean.

TRUE means Head and FALSE means Tails

. Then I toss the coin and I check if the result is the same as the computer random guess.

var random_boolean = Math.random() >= 0.5;
if (random_boolean) {
    save(Heads_count++)
    console.log('I guess: HEAD!!!!!!!!!!!!!!!!!!!!!!')
} else {
   save(Tails_count++)
    console.log('I guess: TAIL!!!!!!!!!!!!!!!!!!!!!!!!')
}

I call it SUCCESS if the two results match. It repeat the same experience several time (N) and I count the number of success.

Weirdly, I get a success rate tending toward 50% . Why is that? Is it normal assuming that the computer generate a fair random boolean and knowing that the coin is unfair?

1

There are 1 best solutions below

3
On BEST ANSWER

Yes, that is normal and in fact doesn't depend on your coin at all. Let us look at two independent random variables with range $\{0,1\}$: $X$ represents your toss, $Y$ represents your computer's guess. Let $P(X = 0) = p$ - the probability of your toss to be '$0$'. Then $$ \begin{align*} P(X = Y) &= P(X = Y = 0 \cup X = Y = 1) \\ &= P(X=0) P(Y=0) + P(X=1)P(Y=1) \\ &= p \cdot 0.5 + (1-p) \cdot 0.5 \\ &= 0.5 \end{align*} $$