129 | Python | mmnow | 2018-11-20 15:56:16 |
import random
import string
charset = string.ascii_letters + string.digits + string.punctuation
def gen(length: int) -> str:
if not 8 <= length <= 256: raise Exception(f"Wrong length: {length}")
return ''.join([random.choice(charset) for i in range(0, length)])