From: W. Trevor King Date: Sun, 24 Oct 2010 18:33:41 +0000 (-0400) Subject: Give src/sorting/data.py the option of generating sorted data. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3fe7b672987d1786241384d48ee2e3ab1b8dde02;p=parallel_computing.git Give src/sorting/data.py the option of generating sorted data. --- 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])