Skip to content

Instantly share code, notes, and snippets.

@kwikwag
Created September 24, 2018 15:39
Show Gist options
  • Save kwikwag/c91b5b9facd52fcd54cada1cc1190440 to your computer and use it in GitHub Desktop.
Save kwikwag/c91b5b9facd52fcd54cada1cc1190440 to your computer and use it in GitHub Desktop.
import argparse
import os
import random
parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()
data = []
read_size = 1024 * 4
with open(args.file, "rb") as in_file:
in_file.seek(0, os.SEEK_END)
size = in_file.tell()
print('File size:', size, 'Read size:', read_size)
for i in range(8000):
pos = random.randrange(size - read_size)
in_file.seek(pos, os.SEEK_SET)
data.append(in_file.read(read_size))
print(sum([ len(page) for page in data]), 'bytes read')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment