import random import string def ranstr(num): salt = ''.join(random.sample(string.ascii_lowercase + string.digits, num)) return salt ranstr(10)