Uniform balanced binary sequence sampling
ID: uniform-balanced-binary-sequence-sampling
A balanced binary sequence of length has entries of each kind. Uniformly sample an -element subset of the positions and place the first kind there. If is a power of two, repeatedly draw uniform positions using fair random bits, reject previously selected positions, and stop after distinct positions. Each new position is uniform among those remaining, making every -element subset equally likely. The expected number of draws is , giving expected random bits.
New to topics? Read the docs here!