随机生成10000个字符串

import random
import string
from time import time
import pickle


strg = 'ABCDEFGHIJKLMNOPQRSTUVEXYZ'
num = 0
string_str = ['A']
timestart = time()
set_01 = set()
print(set_01)
while True:
str_01 = ''
for i in range(0, 5):
j = random.randint(0, 25)
str_01 = str_01 + strg[j]
# print(str_01)

set_01.add(str_01)
length = len(set_01)
if length > 9999:
break

timesend = time()
print(timesend)
print('*' * 200)
print((timesend - timestart))
print('*' * 200)
print(set_01)
print(len(set_01))
print('-' * 200)
#
timestart01 = time()
set02 = set()
while True:
s = (''.join(random.sample(['Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D','C', 'B', 'A'], 5)))
set02.add(s)
if len(set02) >9999:
break
print(set02)
timesend01 = time()
print('*' * 200)
print((timesend01 - timestart01))
print('*' * 200)

with open('stringtext.txt', 'w', encoding='utf-8') as fp:
for index, index_str in enumerate(set02):
# 写入txt文件
fp.write(str(index +1) +' ')
fp.write(index_str + '\n')
posted @ 2021-03-09 12:27  zechariah1  阅读(361)  评论(0编辑  收藏  举报