class 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) {
                    // should never happen
                    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;
    }

}