#!/usr/bin/env python3

"""
sortr [file1] [file2] ...

Like "sort -R", except a random permutation of all lines from the given files.
It doesn't (necessarily) put identical lines together like "sort -R".
If no files are specified, it reads from standard input.
A filename of '-' also specifies standard input.

Alternative: shuf from coreutils, which is probably better.
"""

# Iain Murray, 2014-10-22

import fileinput, random, sys

if (len(sys.argv) > 1) and (sys.argv[1] in ['-h', '--help']):
    sys.stdout.write(__doc__)
    sys.exit(0)

all_lines = []
for line in fileinput.input():
    all_lines.append(line)

random.shuffle(all_lines)

for line in all_lines:
    sys.stdout.write(line)
