Python3 randomly generated password number and length of the custom

# Reference codes made great God, please God forgive big,

# Reference codes made great God, please God forgive big

# Reference codes made great God, please God forgive big

import random

import string

# Python3 for string.ascii_letters, down python2 you can use string.letters and string.ascii_letters

# String.ascii_letters set of uppercase and lowercase letters

#string.digits        0-9

# String.punctuation symbol set

def GenPassword(length):

    chars=string.ascii_letters+string.digits+string.punctuation

    return '' results .join ([random.choice (chars) for i in range (length)]) # drawn characters have duplicate

    # Return '' results obtained .join (random.sample (chars, 15)) # character is not in duplicate

# if __name__=="__main__":

# # Generate 10 random passwords 

#     for i in range(10):

# # Password length is 15

#         # print(i,type(GenPassword(15)))

# Print ( 'Key Group.% D:% s'% (i + 1, GenPassword (15)))

def GP(num,length):

  for i in range(num):

       print ( 'Key Group.% d:% s'% (i + 1, GenPassword (length)))

# 20 test group, 8

GP(20,8)

'''

result:

Group 1 Key: N2Lh-Hz%
Group 2 Key: kw78WQ +]
Group 3 Key: V8XOSqQU
Group 4 Key: Jc - & {gbV
Group 5 Key: Gw) \ Ps {8
6 group key: "G> P% bX +
group key 7: iqP) / r,"
group 8 key: dD3x8 # w>
group 9 key: G \ 0qX] H;
10 group key: riBor [53
11 group key: \ U5 # 7 {5.
12 group key:] 4aC '= Z)
of set key 13: gG / U & 9TG
14 group key: "D ^^ 3c8d
15 group key: h <o; AMuR
16 group key: 8z ~ kQ [S $
17 group key: BPXBA + b #
18 group key: t / ^ 8WvI +
19 group key: # A & {U9KD
group 20 key: wSE2b1Rb

'''

Guess you like

Origin www.cnblogs.com/Q-Q-/p/11207621.html