1 # !/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import random 4 5 schr = [chr(s) for s in range(65,91)] 6 bchr = [chr(b) for b in range(97,123)] 7 num = [str(n) for n in range(0,10)] 8 signs = [‘!‘,‘@‘,‘#‘,‘$‘,‘%‘,‘^‘,‘&‘,‘*‘,‘(‘,‘)‘,‘+‘,‘-‘,‘_‘,‘=‘,‘<‘,‘>‘,‘`‘,‘|‘,‘[‘,‘]‘,‘{‘,‘}‘,‘?‘,‘/‘] 9 codes = schr + bchr + num + signs 10 11 def shuffle(codes): 12 for i in range(5): 13 random.shuffle(codes) 14 return codes 15 16 def get_code(codes): 17 codes = shuffle(codes) 18 rand_start = random.randint(0,len(codes)-12) 19 rand_end = rand_start + 12 20 return ‘‘.join(codes[rand_start:rand_end]) 21 22 print get_code(codes)
时间: 2024-12-23 14:06:45