public void sample(Record rec){
  totalRecs++;
  if (samples.size() < MAX_SAMPLES) {
    samples.add(new Sample(rec,schema));
    updateNewValueInterval(rec);
  }
 else {
    double flip=random.nextDouble();
    if (flip < (double)MAX_SAMPLES / totalRecs) {
      samples.set(random.nextInt(MAX_SAMPLES),new Sample(rec,schema));
      updateNewValueInterval(rec);
    }
  }
}

public void sample ( Record rec ) { totalRecs ++ ; if ( samples . size ( ) < MAX_SAMPLES ) { samples . add ( new Sample ( rec , schema ) ) ; updateNewValueInterval ( rec ) ; } else { double flip = random . nextDouble ( ) ; if ( flip < ( double ) MAX_SAMPLES / totalRecs ) { samples . set ( random . nextInt ( MAX_SAMPLES ) , new Sample ( rec , schema ) ) ; updateNewValueInterval ( rec ) ; } } }
keep a record as a sample , with certain probability . this method is designed to uniformly sample all records of a table under the situation where the total number of records is unknown in advance . a client should call this method when iterating through each record of a table .
