Get N random lines from a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# call with two arguments, the path to the file to read lines from and | |
# the number of lines | |
from sys import argv | |
from random import SystemRandom | |
with open(argv[1]) as f: | |
lines = f.readlines() | |
r = SystemRandom() | |
print( ''.join( r.sample(lines, int(argv[2])) ), end='' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment