code: protected static Selection selectNRowsAtRandom(int n, int max) {
          Selection selection = new BitmapBackedSelection();
          if (n > max) {
              throw new IllegalArgumentException("Illegal arguments: N (" + n + ") greater than Max (" + max + ")");
          }
  
          int[] rows = new int[n];
          if (n == max) {
              for (int k = 0; k < n; ++k) {
                  selection.add(k);
              }
              return selection;
          }
  
          BitSet bs = new BitSet(max);
          int cardinality = 0;
          Random random = new Random();
          while (cardinality < n) {
              int v = random.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)) {
              rows[pos++] = i;
          }
          for (int row : rows) {
              selection.add(row);
          }
          return selection;
      }
docs: Returns an randomly generated selection of size N where Max is the largest possible value