欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python隨機生成大小寫字母數(shù)字混合密碼(僅20行代碼)

 更新時間:2020年02月01日 10:49:51   作者:poisonmmmm  
這篇文章主要介紹了python隨機生成大小寫字母數(shù)字混合密碼,主要是利用random模塊隨機生成數(shù)字,大小寫字母,通過循環(huán)次數(shù)來實現(xiàn)此功能,需要的朋友可以參考下

用簡單的方法生成隨機性較大的密碼

僅用20行代碼隨機生成密碼

核心思路:利用random模塊

random模塊隨機生成數(shù)字,大小寫字母,循環(huán)次數(shù)

while循環(huán)+隨機生成的循環(huán)次數(shù)——>隨機plus++

大寫字母ASKII碼在65-90之間

小寫字母Askll碼在97-122之間

最終效果: x個大寫字母+y個數(shù)字+z個小寫字母(x,y,z均隨機)

隨機性相較于以往單調(diào)的 小寫+數(shù)字+大寫+小寫+數(shù)字+大寫… 循環(huán)有所提升

import random
print("隨機數(shù)生成”)
time=random.randint(1,2)
  while time:
    time1=random.randint(1, 3)
    time2=random.randint(1, 2)
    time3=random.randint(1, 3)
    while time1:
     a= random.randint(65,90)
     print("%c"%a,end="")
     time1-=1
    while time 2:
     c= random.randint(0,99)
     print("%d"%c,end="")
     time2-=1
    while time3:
     b= random.randint(97,122)
     print("%c"%b,end="")
     time 3-=1
  time-=1

補充:用Python隨機生成一個六位驗證碼(驗證碼由數(shù)字和字母組成(大小寫字母))

import random  
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
這里要用到random函數(shù)中的隨機生成一個區(qū)間的整數(shù) randint 函數(shù)模塊 
第一次知道循環(huán)可以這樣用 for _ in range():
hhh
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
def generate_code(code_len = 6):
  all_char = '0123456789qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJIKOLP'
  index = len(all_char) + 1
  code = ''
  for _ in range(code_len):
    num = random.randint(0,index)
    code += all_char[num]
  return code 
print(generate_code())

總結(jié)

以上所述是小編給大家介紹的python隨機生成大小寫字母數(shù)字混合密碼(僅20行代碼),希望對大家有所幫助!

相關文章

最新評論