I'm writing a tool for manually collecting entropy from sources like coins and dice, and I'm wondering how to best deal with the case where the desired number of bits of entropy is not representable with a whole number of inputs. For example, when collecting 256 bits of entropy with a D6; log6(2^256) = 99.034318652
.
The number of bits being collected, and the base, are arbitrary. Power-of-two bases are special cased to work directly with bits, as well as offering Von Neumann skew correction. Non-power-of-two bases are collected with a big integer: aggregate = aggregate * base + input
where input
is a value inclusively from 0 to base-1
.
The simple solution which springs to mind is rounding (ceil, floor or true rounding) the number of inputs, but I'm not sure which strategy would be best, or whether there is some better option to minimize at least the predictability of biased bits in the result (my instinct is 'doing something with a CHF', but I've no idea what).
Cheers!
X^N % 2^Y
values occur once more in the possible output than the other2^Y - (X^N % 2^Y)
values. $\endgroup$