码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-08-29 00:22:36      阅读:521      评论:0      收藏:0      [点我收藏+]

标签:shuffle   python   import   密码   

  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)


本文出自 “bobo的运维之路” 博客,转载请与作者联系!

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

标签:shuffle   python   import   密码   

原文地址:http://shiyiguo.blog.51cto.com/4949751/1843548

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!