python生成任意位数的验证码(只有数字+大小写字母)

# 方法一
import random
import string
totle_string = string.ascii_letters + string.digits
def auth_code(num):
	res = ''.join(random.sample(totle_string, num)) 
	return res


# 方法二
import random
import string
totle_string = string.ascii_letters + string.digits
def auth_code(num):
	l = [i for i in totle_string]
	random.shuffle(l)
	return ''.join(l[0:num])

你可能感兴趣的:(python)