szaydel
7/22/2013 - 8:15 PM

Simple script that returns a random string of XX characters long when a numeric argument of XX is passed as argv1.

Simple script that returns a random string of XX characters long when a numeric argument of XX is passed as argv1.

#!/usr/bin/env python
__author__ = 'szaydel'

from string import ascii_letters
from string import digits
from sys import argv
from random import choice

args = argv[1:]
chars = list(ascii_letters+digits)

for arg in args:
    result = []
    try:
        le = abs(int(arg))
        for i in range(0, le):
            result.append(chars[choice(range(0, chars.__len__()))])
        print "String[{0}]=> {1}".format(arg, "".join(result))

    except ValueError as v:
        pass