random.py
#Hexadécimal(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]
#Cas de l'alphabet+Nombres(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