I have written the following python project which provides a random output of 20 strings and I have set the limit of it to be less than 1,00,000 during each run and every string shall be unique.
Now I want to add a line of code that helps me start each output with a number
To make it more simple here is an example:
Output right now: AtcaF268d1whnkwiwuniw
Output I need: 7atcaF268d1whnkwiwuni
So each output is a random number.
Here is the code to edit
import random
results = []
while len(results) < 100000:
result_str = ''.join((random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for i in range(20)))
if result_str not in results:
results.append(result_str)
with open('string_test.txt','a') as out:
out.write( '\n'.join(results) )
>Solution :
just gernerate it seperatly i guess?
import random
results = []
while len(results) < 100000:
result_str = random.choice('0123456789') + ''.join((random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') for i in range(19)))
if result_str not in results:
results.append(result_str)
with open('string_test.txt','a') as out:
out.write( '\n'.join(results) )