3

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?

VividD
  • 15,966
TSR
  • 507
  • If I understand you correctly you're flipping a weighted coin and comparing it to guesses based on code assuming a fair weight for each side. Why not write code that does both, run through it a million or so times and compare those. It might not be correct (an answer below does disagree) but my instinct tells me you shouldn't get 50% success. – FreeElk May 27 '17 at 12:14
  • Strike that, I have just had a look and the answer below convinces me mathematically, however much my instinct dislikes it :P – FreeElk May 27 '17 at 12:23

1 Answers1

3

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*} $$

Stefan Mesken
  • 16,651
  • you mentioned: "It doesn't depend on your coin at all". Does this mean that whether the coin is totally random or totally arranged (like following a function, or a deterministic sequence), it doesn't matter, the success of guessing its value through random algorithm will always be 50%? – TSR May 27 '17 at 12:34
  • What I meant is that it doesn't depend on the value of $p$ above. – Stefan Mesken May 27 '17 at 12:35
  • Omg, this is true. – TSR May 27 '17 at 20:33