code: int[] generateUniformBitmap(int N, int Max) {
                  if (N > Max)
                          throw new RuntimeException("not possible");
                  int[] ans = new int[N];
                  BitSet bs = new BitSet(Max);
                  int cardinality = 0;
                  while (cardinality < N) {
                          int v = rand.nextInt(Max);
                          if (!bs.get(v)) {
                                  bs.set(v);
                                  cardinality++;
                          }
                  }
                  int pos = 0;
                  for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
                          ans[pos++] = i;
                  }
                  return ans;
          }
docs: generates randomly N distinct integers from 0 to Max.