Give src/sorting/data.py the option of generating sorted data.
authorW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 18:33:41 +0000 (14:33 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 18:33:41 +0000 (14:33 -0400)
src/sorting/data.py

index 1d948ff2b8393da18b734586aa75f69e3613ed6b..b3aa13c61c3dbbb23596ab07f3d33c0f13d9302d 100755 (executable)
@@ -1,11 +1,32 @@
 #!/usr/bin/env python
 
+"""Generate random (or ordered) data for sorting.
+
+Output format:
+
+    # <N>
+    <point 1>
+    <point 2>
+    <point 3>
+    ...
+    <point N>
+"""
+
+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])