返回题库

用硬币从均匀分布采样

How to Sample From a Uniform Distribution Using a Coin

专题
Probability / 概率
难度
L2

题目详情

如何仅用一枚公平硬币,在区间 [0,1][0,1] 上采样一个均匀随机数?

How can we sample from a uniform distribution over [0,1][0, 1] using a fair coin?

解析

用二进制展开。

不断抛硬币:正面记为 1,反面记为 0,得到序列 b1b2b_1b_2\cdots

将其解释为二进制小数:

U=0.b1b2b32=i1bi2i.U=0.b_1b_2b_3\cdots_2=\sum_{i\ge 1} b_i 2^{-i}.

UU[0,1][0,1] 上均匀分布。实际中抛有限次得到近似。


Original Explanation

To sample from a uniform distribution [0,1][0, 1] using a fair coin, we utilize the binary representation of numbers between 0 and 1. Each flip of the coin gives us a binary digit, and the sequence of coin flips can be interpreted as a binary fraction.

Method

  1. Flip the coin. If it’s heads, the first binary digit after the point is 1. If it’s tails, the digit is 0.
  2. Continue flipping the coin to obtain subsequent binary digits.
  3. Interpret the resulting sequence of heads and tails as a binary fraction.

For example, a sequence of HTHT corresponds to the binary representation 0.110120.1101_2, which in decimal form is: 0.5+0.25+0.0+0.125=0.8750.5 + 0.25 + 0.0 + 0.125 = 0.875

However, with a finite number of coin flips, we can only approximate numbers in [0,1][0, 1] to a certain precision. The more flips we use, the finer the resolution of our approximation.