用硬币从均匀分布采样
How to Sample From a Uniform Distribution Using a Coin
题目详情
如何仅用一枚公平硬币,在区间 上采样一个均匀随机数?
How can we sample from a uniform distribution over using a fair coin?
解析
用二进制展开。
不断抛硬币:正面记为 1,反面记为 0,得到序列 。
将其解释为二进制小数:
则 在 上均匀分布。实际中抛有限次得到近似。
Original Explanation
To sample from a uniform distribution 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
- Flip the coin. If it’s heads, the first binary digit after the point is 1. If it’s tails, the digit is 0.
- Continue flipping the coin to obtain subsequent binary digits.
- Interpret the resulting sequence of heads and tails as a binary fraction.
For example, a sequence of HTHT corresponds to the binary representation , which in decimal form is:
However, with a finite number of coin flips, we can only approximate numbers in to a certain precision. The more flips we use, the finer the resolution of our approximation.