decode_uniform() should read ceil(log2(x)) bits, not log2(x).