How to pick exactly k bits from a Java BitSet of length m with n bits turned on, where k≤n≤m?
k
m
n
k≤n≤m
Example input: m=2
m=2
How about finding n positions of all set bits and placing them in a collection as the first step, and them choosing k positions from that collection randomly?