def sample(reader, writer, n, start=None, stop=None, tsCol=None,<EOL>writeSampleOnly=True):
rows = list(reader)<EOL>if tsCol is not None:<EOL><INDENT>ts = rows[<NUM_LIT:0>][tsCol]<EOL>inc = rows[<NUM_LIT:1>][tsCol] - ts<EOL><DEDENT>if start is None:<EOL><INDENT>start = <NUM_LIT:0><EOL><DEDENT>if stop is None:<EOL><INDENT>stop = len(rows) - <NUM_LIT:1><EOL><DEDENT>initialN = stop - start + <NUM_LIT:1><EOL>numDeletes =  initialN - n<EOL>for i in range(numDeletes):<EOL><INDENT>delIndex = random.randint(start, stop - i)<EOL>del rows[delIndex]<EOL><DEDENT>if writeSampleOnly:<EOL><INDENT>rows = rows[start:start + n]<EOL><DEDENT>if tsCol is not None:<EOL><INDENT>ts = rows[<NUM_LIT:0>][tsCol]<EOL><DEDENT>for row in rows:<EOL><INDENT>if tsCol is not None:<EOL><INDENT>row[tsCol] = ts<EOL>ts += inc<EOL><DEDENT>writer.appendRecord(row)<EOL><DEDENT>
Samples n rows.

    Args:
      reader: A FileRecordStream object with input data.
      writer: A FileRecordStream object to write output data to.
      n: The number of elements to sample.
      start: The first row in the range to sample from.
      stop: The last row in the range to sample from.
      tsCol: If specified, the timestamp column to update.
      writeSampleOnly: If False, the rows before start are written before the
          sample and the rows after stop are written after the sample.