### Question:
AnalyzeUtils { static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { throw new IllegalArgumentException( "Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }  static List<Fragment> getSampleFragments(List<Fragment> fragments,
                                                    RequestContext context); static BitSet generateSamplingBitSet(int poolSize, int sampleSize);  }### Answer:
@Test public void generateSamplingBitSet() throws Exception { runGenerateSamplingBitSetTest(10, 5, new int[]{0, 3, 4, 6, 9}); runGenerateSamplingBitSetTest(9, 8, new int[] {0, 2, 3, 4, 5, 6, 7, 8}); runGenerateSamplingBitSetTest(10, 10, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); runGenerateSamplingBitSetTest(8, 0, new int[]{}); runGenerateSamplingBitSetTest(8, 3, new int[]{0, 3, 6}); }
@Test public void generateSamplingBitSetBig() throws Exception { BitSet result = AnalyzeUtils.generateSamplingBitSet(1000000, 990000); assertEquals(result.cardinality(), 990000); assertTrue(result.length() < 1000000); result = AnalyzeUtils.generateSamplingBitSet(1000000000, 5000000); assertEquals(result.cardinality(), 5000000); assertTrue(result.length() < 1000000000); }