# -*- coding: UTF-8 -*-
‘‘‘
32-47:空格 ! " # $ % & ‘ ( ) * + , - . /
48-57:0-9
58-64:: ; < = > ? @
65-90:A-Z
91-96:[ 反斜杠 ] ^ _ `
97-122:a-z
123-126:{ | } ~
‘‘‘
import random
from scipy.special import comb, perm
def random_str(code_len=5):
code=‘‘.join([chr(i) for i in range(32,127)])
code_count=int(comb(len(code),code_len))
count= 0
while count < code_count:
checkcode= ‘‘
for i in range(code_len):
j=random.randint(0,len(code)-1)
checkcode+= code[j]
print(checkcode)
count+=1
def sub_list(length=5):
chars = [chr(j) for i in range(length) for j in range(32,127)]
for i in range(1 << len(chars)):
combo_list = []
for j in range(len(chars)):
if i & (1 << j):
combo_list.append(chars[j])
sub_list_len = len(combo_list)
if sub_list_len != length:
continue
else:
sub_str = ‘‘.join(combo_list)
print(sub_str)
def main():
random_str()
sub_list()
if __name__ == ‘__main__‘:
main()
原文:https://www.cnblogs.com/navysummer/p/12124750.html