Skip to content

Instantly share code, notes, and snippets.

@grancalavera
Created May 25, 2014 18:23
Show Gist options
  • Save grancalavera/e66122c5ac8f4735eccb to your computer and use it in GitHub Desktop.
Save grancalavera/e66122c5ac8f4735eccb to your computer and use it in GitHub Desktop.
Creates files with scrambled unique integers
import sys
from random import shuffle
import argparse
"""
usage:
~ python scrambled-integers.py 1200
1200 scrambled integers written to "1200.txt"
"""
def scrambled(orig):
dest = orig[:]
shuffle(dest)
return dest
def main():
parser = argparse.ArgumentParser(prog='Creates an scrambled list of integers\nand saves it to a file, one integer per line')
parser.add_argument('n', help='length of the list', type=int)
args = parser.parse_args()
filename = '%s.txt' % args.n
f = open(filename, 'w+')
for i in scrambled(range(1, args.n + 1)):
f.write('%s\n' % i)
print '%s scrambled integers written to "%s"' % (args.n, filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment