From 521b4fda832cfb338d518533c7616faf0bc31a76 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 5 Jul 2015 20:00:27 +0200 Subject: Support sampling --- rl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'rl') diff --git a/rl b/rl index 316e23c..e5a6a92 100755 --- a/rl +++ b/rl @@ -28,13 +28,21 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - +import argparse import random import sys +parser = argparse.ArgumentParser(description='Process some integers.') +parser.add_argument('-s', '--sample', metavar='LINES', type=int, nargs='?', const=1, help='Print only this many lines (1).') +args = parser.parse_args() + lines = sys.stdin.readlines() -random.SystemRandom().shuffle(lines) +r = random.SystemRandom() +if args.sample is None: + r.shuffle(lines) +else: + lines = r.sample(lines, args.sample) for l in lines: print(l, end='') -- cgit v1.2.3