6 ms·
I like popcount for converting a 2^N-bit uniformly-distributed random number into a N-bit binomially-distributed one. Each bit of the input simulates a random c
by geoffhill 7y ago
I like popcount for converting a 2^N-bit uniformly-distributed random number into a N-bit binomially-distributed one. Each bit of the input simulates a random coin flip.
- eru 7y agoYou are a wasting a lot of random bits this way, don't you?
- adtac 7y agoNot if you already have 2^n bits at hand. In fact, if you have 2^n bits of entropy, popcount is probably more efficient than generating n more bits randomly.
- JoachimSchipper 7y agoSure, but generating random bits is fast with e.g. AES-NI, RdRand or a software implementation of e.g. ChaCha.