tag:blogger.com,1999:blog-11788780.post5618887376328651559..comments2023-12-29T13:22:33.104-08:00Comments on JJinuxLand: Python: Getting a Fair Flip out of an Unfair Coinjjinuxhttp://www.blogger.com/profile/03270879497119114175noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-11788780.post-26396671323874042102011-06-03T15:34:25.454-07:002011-06-03T15:34:25.454-07:00We have a task on this very topic here: http://ros...We have a task on this very topic here: http://rosettacode.org/wiki/Unbias_a_random_generator, so you can see it solved in Python and other languages.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-74238174607232818452011-06-03T15:25:15.709-07:002011-06-03T15:25:15.709-07:00> You've reinvented the von Neumann Extract...> You've reinvented the von Neumann Extractor, and Jean-Paul is right about the reasons it works for a biased but non-autocorrelated source.<br /><br />Nice job providing the reference. I'm 100% okay with the fact that I came up with the same thing as Von Neumann ;)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-60197949927685244232011-06-03T15:21:32.670-07:002011-06-03T15:21:32.670-07:00> It works because...
Wow, great explanation!> It works because...<br /><br />Wow, great explanation!jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-61423879570189743592011-06-03T15:20:33.025-07:002011-06-03T15:20:33.025-07:00> While we're at it, there's a typo in ...> While we're at it, there's a typo in the script: you write "Prove" but you merely demonstrate. <br /><br />Updated. Thanks.jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-73819666443398662692011-06-03T11:49:12.946-07:002011-06-03T11:49:12.946-07:00You've reinvented the von Neumann Extractor, a...You've reinvented the <a href="http://en.wikipedia.org/wiki/Randomness_extractor#Von_Neumann_extractor" rel="nofollow">von Neumann Extractor</a>, and Jean-Paul is right about the reasons it works for a biased but non-autocorrelated source.Jeff Eplerhttp://emergent.unpy.net/noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-28990499416478386062011-06-03T11:30:32.292-07:002011-06-03T11:30:32.292-07:00Very neat!
@Dirk: it works because even biased co...Very neat!<br /><br />@Dirk: it works because even biased coin flips are still independent. (if they are not e.g. if a person is controlling the flips, or the coin has been set to do a certain sequence, this method will fail).<br /><br />Essentially, you are flipping the coin twice, and then only looking at the times when the two results are different. The first time you get that scenario, pick the first result (or last, it doesn't matter). The probability of getting Heads then Tails is the same as the probability of getting Tails then Heads (due to independence), so you get odds of 50% for the overall result being Heads or Tails.Luke Planthttps://www.blogger.com/profile/10988266347497131512noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-10287284680067568582011-06-03T11:25:56.891-07:002011-06-03T11:25:56.891-07:00It works because even on an unfair coin, the chanc...It works because even on an unfair coin, the chance of a heads followed by a tails is the same as the chance of a tails followed by a head. This algorithm only returns a value when one result is followed by the other. Looking at the possible outcomes makes this pretty clear. If heads is .7 and tails is .3, then the four possible outcome probabilities are:<br /><br />heads/heads = 0.49<br />heads/tails = 0.21<br />tails/heads = 0.21<br />tails/tails = 0.09<br /><br />The algorithm throws away heads/heads and tails/tails and returns tails for heads/tails and heads for tails/heads - each with a probability of of 0.21 per attempt (with transparent re-tries for the rejected cases).Jean-Paul Calderonehttps://www.blogger.com/profile/15144405957500773467noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-90008610637016688642011-06-03T11:18:09.567-07:002011-06-03T11:18:09.567-07:00It works, but I don't really understand why (t...It works, but I don't really understand why (that's what happens when you don't learn statistics). An explanation would be nice...<br /><br />While we're at it, there's a typo in the script: you write "Prove" but you merely demonstrate.Dirk Bergstromnoreply@blogger.com