Tuesday, August 20, 2013

Python - Generate random string

If you want to create a random string in python, here you are:


#!/user/bin/python
import string
import random


def id_gen(size=6, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for x in range(size))