#coding:utf-8import random,stringdef GetPassword(length): # 隨機生成數字個數 Ofnum=random.randint(1,length) Ofletter=length-Ofnum # 選中ofnum個數字 slcNum=[random. ...
#coding:utf-8
import random,string
def GetPassword(length):
# 隨機生成數字個數
Ofnum=random.randint(1,length)
Ofletter=length-Ofnum
# 選中ofnum個數字
slcNum=[random.choice(string.digits) for i in range(Ofnum)]
# 選中ofletter個字母
slcLetter=[random.choice(string.ascii_letters) for i in range(Ofletter)]
# 打亂組合
slcChar=slcLetter+slcNum
random.shuffle(slcChar)
# 生成隨機密碼
getPwd=''.join([i for i in slcChar])
return getPwd
if __name__=='__main__':
print( GetPassword(6)) #GetPassword()自定義隨機密碼長度