1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- class Produce:
-
- __rand_num = list()
-
- __abandon = set()
-
- @classmethod
- def __vessel(cls, option='num or letter'):
-
- cls.__rand_num = list()
- if option == 'num':
-
- for i in range(10):
- cls.__rand_num.append(str(i))
- elif option == 'letter':
-
- for i in range(26):
- cls.__rand_num.append(chr(i + 65))
- cls.__rand_num.append(chr(i + 97))
- elif option == 'num or letter':
-
- for i in range(10):
- cls.__rand_num.append(str(i))
-
- for i in range(26):
- cls.__rand_num.append(chr(i + 65))
- cls.__rand_num.append(chr(i + 97))
- else:
- print('参数option传递错误!!!')
- print("option='num' or 'letter'")
- import sys
- sys.exit()
-
- @classmethod
- def auth_code(cls, option='num or letter', num=6):
- buf = ''
- cls.__vessel(option=option)
- from random import choice
- for i in range(num):
- buf += choice(cls.__rand_num)
-
- if cls.__abandon == set():
- cls.__abandon.add(buf)
- return buf
-
- for i in cls.__abandon:
-
- if buf == i:
- buf = cls.auth_code(option=option, num=num)
- return buf
-
- cls.__abandon.add(buf)
- return buf
-
- @classmethod
- def check_data(cls):
- print(f'随机数库:{cls.__rand_num}')
- print('废弃站:{}'.format(cls.__abandon))
-
- @classmethod
- def clear_abandon(cls):
- cls.__abandon.clear()
- if __name__ == '__main__':
- for i in range(100):
- num = Produce.auth_code(option='num')
- print(Produce.auth_code(option='num'))
|