defgenerate_pass(length, array, is_alpha=False): for i inrange(length): index = random.randint(0, len(array) - 1) character = array[index] if is_alpha: case = random.randint(0, 1) ifcase == 1: character = character.upper() password.append(character)
最后,调用处理密码字符串的方法,合并所有处理好的字符串,并随机排列一次,打印出来。
1 2 3 4 5 6 7 8 9 10 11 12 13
# 英文字母 generate_pass(alpha_len, alpha, True) # 数字 generate_pass(num_len, num) # 特殊字符 generate_pass(special_len, special) # 随机排列所有字符 random.shuffle(password) # convert List To string gen_password = "" for i in password: gen_password = gen_password + str(i) print(gen_password)
defgenerate_pass(length, array, is_alpha=False): for i inrange(length): index = random.randint(0, len(array) - 1) character = array[index] if is_alpha: case = random.randint(0, 1) ifcase == 1: character = character.upper() password.append(character)
# 英文字母 generate_pass(alpha_len, alpha, True) # 数字 generate_pass(num_len, num) # 特殊字符 generate_pass(special_len, special) # 随机排列所有字符 random.shuffle(password) # convert List To string gen_password = "" for i in password: gen_password = gen_password + str(i) print(gen_password)