Randomly pick k bits out of n from a Java BitSet

后端 未结 4 709
無奈伤痛
無奈伤痛 2021-01-21 08:42

How to pick exactly k bits from a Java BitSet of length m with n bits turned on, where k≤n≤m?

Example input: m=2

4条回答
  •  灰色年华
    2021-01-21 08:51

    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?

提交回复
热议问题