lukyjyt 发表于 2016-8-29 09:20:58

python 利用random的shuffle洗牌方法生产1个12位数的随机密码



1 # !/usr/bin/env python                                                         
2 # -*- coding:utf-8 -*-                                                         
3 import random                                                                  
4                                                                                 
5 schr =                                           
6 bchr =                                           
7 num =                                              
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)                                 
21                                                                                 
22 print get_code(codes)




页: [1]
查看完整版本: python 利用random的shuffle洗牌方法生产1个12位数的随机密码