public void add(T t) {
    if (n < k) {
      r.add(t);
    } else {
      int j = ThreadLocalRandom.current().nextInt(n + 1);
      if (j < k) {
        r.set(j, t);
      }
    }
    n++;
  }
The simple version of reservoir sampling implementation. It is enough for the usage in HBase.
<p/>
See https://en.wikipedia.org/wiki/Reservoir_sampling.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReservoirSample.java