BitSetUtils { public static BitSet getRandomBits(int n, Random random) { BitSet bits = new BitSet(n); for (int i = 0; i < n; i++) { bits.set(i, random.nextBoolean()); } return bits; } private  BitSetUtils(); static BitSet copy(BitSet b); static BitSet getRandomBits(int n, Random random); static String toString(BitSet bits, int n); static String toString(BitSet bits); static boolean innerProduct(BitSet a, BitSet b); static BitSet fromList(List<Boolean> list); static BitSet fromArray(boolean[] array); static boolean[] toArray(BitSet bitset, int length); static List<Boolean> toList(BitSet bitset, int n);  }
@Test public void testGetRandomBits() { final int limit = 100; Random rand1 = new Random(0); BitSet b = BitSetUtils.getRandomBits(limit, rand1); Random rand2 = new Random(0); for (int i = 0; i < limit; i++) { Assert.assertEquals(rand2.nextBoolean(), b.get(i)); } }