Would there be an efficient way to implement a function with the following signature:
unsigned long long int random_word(size_t n, size_t m)
that would generate a random machine word (64 bits here) such that exactly
m bits over the
n least significant ones at set to
1. For example:
random_word(10, 3) would generate a 64-bit random number such that 3 bits over the 10 LSBs are set to
1. For a given
m every possible output should have equal probability (uniform distribution of possible permutations).
If assembly bit twiddling hacks to do that are known, great, if not, I am looking for references and research directions.