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) {
    console.log('I guess: HEAD!!!!!!!!!!!!!!!!!!!!!!')
} else {
    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?

  • $\begingroup$ 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. $\endgroup$ – FreeElk May 27 '17 at 12:14
  • $\begingroup$ Strike that, I have just had a look and the answer below convinces me mathematically, however much my instinct dislikes it :P $\endgroup$ – FreeElk May 27 '17 at 12:23

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

  • $\begingroup$ 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%? $\endgroup$ – TSR May 27 '17 at 12:34
  • $\begingroup$ What I meant is that it doesn't depend on the value of $p$ above. $\endgroup$ – Stefan Mesken May 27 '17 at 12:35
  • $\begingroup$ Omg, this is true. $\endgroup$ – TSR May 27 '17 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.