3 ms·
Some useful distributions: * Generate a random number in [1, NUMBITS], then generate a random number with that many bits. * Generate a random number and count
by o11c 3y ago
Some useful distributions:
* Generate a random number in [1, NUMBITS], then generate a random number with that many bits.
* Generate a random number and count its trailing (or leading, if easier in your environment) zeroes, then generate a random number with that many bits. Be sure to correctly handle the case where the first random number is zero.
* Generate two random numbers and take the minimum.