random.py
#Hexadecimal(0-9, a-f)
def gen_rand_str_hex(length):
import os
import hashlib
buf = ''
while len(buf) < length:
buf += hashlib.md5(os.urandom(100)).hexdigest()
return buf[0:length]
#Uppercase and lowercase letters+Numbers(0-9, a-z, A-F)
def gen_rand_str(length, chars=None):
import random
import string
if chars is None:
chars = string.digits + string.letters
return ''.join([random.choice(chars) for i in range(length)])
Recommended Posts