From 3fe7b672987d1786241384d48ee2e3ab1b8dde02 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 24 Oct 2010 14:33:41 -0400 Subject: [PATCH] Give src/sorting/data.py the option of generating sorted data. --- src/sorting/data.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/sorting/data.py b/src/sorting/data.py index 1d948ff..b3aa13c 100755 --- a/src/sorting/data.py +++ b/src/sorting/data.py @@ -1,11 +1,32 @@ #!/usr/bin/env python +"""Generate random (or ordered) data for sorting. + +Output format: + + # + + + + ... + +""" + +import optparse import random import sys -N = int(sys.argv[1]) +p = optparse.OptionParser(usage='%prog [options] N_POINTS', epilog=__doc__) +p.add_option('-o', '--ordered', dest='shuffle', default=True, + action='store_false', help="Don't shuffle the output data.") + +options,args = p.parse_args() + +N = int(args[0]) data = range(N) -random.shuffle(data) + +if options.shuffle: + random.shuffle(data) print '# %d' % N print '\n'.join([str(x) for x in data]) -- 2.26.2