code: def _shuffle_tfrecord(path, random_gen):
    
    # Read all records
    record_iter = tf.compat.v1.io.tf_record_iterator(path)
    all_records = [
        r for r in utils.tqdm(
            record_iter, desc="Reading...", unit=" examples", leave=False)
    ]
    # Shuffling in memory
    random_gen.shuffle(all_records)
    # Write all record back
    with tf.io.TFRecordWriter(path) as writer:
      for record in utils.tqdm(
          all_records, desc="Writing...", unit=" examples", leave=False):
        writer.write(record)
docs: Shuffle a single record file in memory.