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

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

7
with open(filename) as f:
8 9 10 11 12
    lines = f.readlines()

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

for ln in linestoprint:
13
    print(lines[ln], end='')