random_lines.py 272 Bytes
Newer Older
1 2 3 4 5 6
import sys
import random

number = int(sys.argv[1])
filename = sys.argv[2]

root's avatar
root committed
7
with open(filename, encoding='utf-8') as f:
8 9 10 11 12
    lines = f.readlines()

linestoprint = random.sample(range(len(lines)), number)

for ln in linestoprint:
root's avatar
root committed
13
    print(lines[ln].encode('utf8'), end='')