Hacker News new | ask | show | jobs
by peeters 1725 days ago
This doesn't seem quite right, unless I'm misunderstanding. If your bias was 128 (10000000) by your algorithm you would get heads at least 50% of the time (heads on the first flip) and tails at least 25% of the time (heads then tails). I think instead of taking the "wrong" flip result when they don't match, you should treat "getting to the end" as heads and failing before that as tails (or vice versa).
1 comments

p is a probability in range [0, 1]. So if p = 1/128, the expansion is 0.0000001.

In this case the algorithm says you return tails unless you flip 7 heads in a row (which happens with probability 1/128).

Ah thanks for the explanation. Makes a lot more sense with the fractional expansion.