TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Make a Fair Coin from a Biased Coin (2018)

95 点作者 leonry大约 3 年前

12 条评论

eru大约 3 年前
Von Neumann&#x27;s solution is clever, but extremely inefficient in terms of how many flips you need per random bit produced.<p>More interesting methods produce a stream of unbiased random bits out of a stream of flips; and you can look at the asymptotic efficiency.<p>A simple method to run better than von Neumann&#x27;s method:<p>Produce 1,000 coin flips. Say you produce k heads and 1,000-k tails.<p>Produce a table of all possible sequences of length 1,000 with k heads and 1,000-k tails.<p>Look up the position of your actual realized sequence in that table. The index of that position is a uniform random integer in a range from 1 to the size of the table.<p>Use your favourite method to extract unbiased bits from that unbiased integer.<p>The only requirement to make the above method work is that coin flips are i.i.d., ie independent and identically distributed.<p>(In practice you probably don&#x27;t want to actually construct the table, but instead compute the index directly as-if you had constructed the table.<p>You might also want to work with arbitrary number of flips, instead of a fixed 1,000; or even adopt the method to an arbitrary length stream of coin flips that you don&#x27;t know in advance.<p>Also in practice, you don&#x27;t need to store the whole sequence. What you do is keep a count of how many heads and tails you&#x27;ve seen so far, but feed the individual coin flips into an &#x27;entropy pool&#x27;. Your head&#x2F;tail count will inform your estimate of how many bits of entropy you have in your pool. (It basically feeds into the formula for how many possible orders of arrangement you have, similar to the fixed-size method suggested above.)<p>You generate your unbiased bits by draining the from the entropy pool.<p>The method of entropy pools described here is pretty much how &#x2F;dev&#x2F;random works on Linux.)
评论 #30696702 未加载
评论 #30696810 未加载
评论 #30698488 未加载
评论 #30697318 未加载
评论 #30696571 未加载
评论 #30697071 未加载
paulmd大约 3 年前
despite all the theoretical work, it&#x27;s not physically possible to bias a coin to any notable degree. Unlike a die you can&#x27;t weight one of the faces, you can bend the coin but it takes about a 90 degree bend in a coin to be able to say that a coin is biased with statistical confidence. Or in other words, if the coin appears reasonably flat, it&#x27;s fair enough that you won&#x27;t notice.<p><a href="https:&#x2F;&#x2F;izbicki.me&#x2F;blog&#x2F;how-to-create-an-unfair-coin-and-prove-it-with-math.html" rel="nofollow">https:&#x2F;&#x2F;izbicki.me&#x2F;blog&#x2F;how-to-create-an-unfair-coin-and-pro...</a><p>I get the idea as shorthand for a binary outcome, but the way you make a coin fair is to flip it.
评论 #30695038 未加载
评论 #30695116 未加载
评论 #30695866 未加载
评论 #30694622 未加载
评论 #30700310 未加载
评论 #30695657 未加载
评论 #30694847 未加载
评论 #30698416 未加载
评论 #30696063 未加载
sidedishes大约 3 年前
A similar cute trick for making a coin with arbitrary bias p out of a fair coin: go through the (possibly infinite) binary expansion of p, flipping once for each digit. If you flip tails on a 1 or heads on a 0, go to the next digit and repeat. If you flip heads on a 1 or tails on a 0, stop and take that as your flip. (And if you get to the end of the expansion, you can think of it as only 0s now, so interpret it as tails)
评论 #30694759 未加载
评论 #30696284 未加载
评论 #30694653 未加载
评论 #30697036 未加载
Animats大约 3 年前
That&#x27;s useful when you want random bits from a pulse noise source, such as radioactive decay. Count pulses over a period of time, and take the last bit of the count. Do this twice. 10 =&gt; 1, 01 =&gt; 0, 00, 11 =&gt; retry.<p>It seems to be a corollary that you cannot get random bits at a guaranteed rate that way.
评论 #30694741 未加载
alberto_ol大约 3 年前
Original Von Neumann paper, the method is described in the second paragraph:<p><a href="https:&#x2F;&#x2F;mcnp.lanl.gov&#x2F;pdf_files&#x2F;nbs_vonneumann.pdf" rel="nofollow">https:&#x2F;&#x2F;mcnp.lanl.gov&#x2F;pdf_files&#x2F;nbs_vonneumann.pdf</a>
fennecs大约 3 年前
Makes me think of some sort of symmetrisation.<p>So for a 6 sided dice, you roll it 6 times in a row. You discard your 6 rolls unless you get a permutation of {1,2,3,4,5,6}, and in that case pick one of the rolls consistently, eg the first or the last.
评论 #30696259 未加载
wildmanx大约 3 年前
For certain P, optimizations are possible.<p>For example, with P=1&#x2F;3, the general method discards TT (P=1&#x2F;9) and HH (P=4&#x2F;9) and repeats, while keeping HT and TH (P=2&#x2F;9 each). One could optimize this by only discarding TT while returning 0 for TT (P=4&#x2F;9) and returning 1 for HT and TH (P=2&#x2F;9 each, together also 4&#x2F;9).<p>Generally we just want to partition the event space into three parts such that two are equally likely while the third one is used to &quot;scratch that, just repeat&quot;. Keeping HT and TH guarantees that, but if you want to minimize retries, better solutions are possible.
hackernewsb大约 3 年前
I have a generally-applicable approach, i.e., a coin with any number of sides and any probabilities. Here we go, in the spirit of brute force:<p>0. Train your wrist, &#x27;cause you&#x27;ll be flipping this a gazillion times (say just N times)<p>1. Enumerate all possibilities, i.e., sample space = {H, T}^N<p>2. Compute the probabilities of each.<p>3. Partition the sample space into two such that the total probability (sum of probabilities) is equal to 0.5.<p>4. Call one element of the partition heads and the other tails.<p>5. Want a &quot;multi-sided-coin&quot;? Go back to step 3 and create a finer partition.
评论 #30699095 未加载
sjaak大约 3 年前
See also the paper &quot;Streaming Algorithms for Optimal Generation of Random Bits&quot;<p><a href="https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1209.0730.pdf" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1209.0730.pdf</a>
评论 #30696292 未加载
odyssey7大约 3 年前
What if the coin&#x27;s bias changes from flip to flip, perhaps influenced by its earlier results? Is there a solution for this?
评论 #30695867 未加载
评论 #30697891 未加载
评论 #30695745 未加载
amitport大约 3 年前
I would say that the second coin is unfair but it&#x27;s not &quot;unbiased&quot; in the statistics sense. It has an expected mean and taking the sample mean of flips will converge to it.
riccardomc大约 3 年前
I thought this was about _crypto_ coins and their inherent unfair distribution.<p>I guess I need to go out more.