Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,128 questions

40,777 answers

573 users

How to generate N random strings in Python

3 Answers

0 votes
import random 
import string 
 
N = 5

for i in range(N):
    s = ''.join([random.choice(string.ascii_letters + string.digits + ':.,#') for i in range(30)]) 
    print(s) 
  
  
  
'''
run:
  
JflJzbZ8N,:llXaAJB:,O5teEIZw0,
9urUSC6wCNjHX9JKEooiRRhL9YOno3
3kYYd41MhsCjWto.54VJ:,jUScXg8r
mjYoWRUPgsz7.7QfNVmGD2pLNs1kKU
qS2BqygQbsO1yTXsFVF:B5Y#tcKIEI
  
'''

 





answered Feb 16, 2020 by avibootz
edited Apr 13, 2021 by avibootz
0 votes
import string
import random

N = 5
length = 10

for x in range(N):
    print(''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length)))


 
 
 
'''
run:
 
6RbaLIqPEQ
EABcVSMjS3
cjSiaNTCgy
s5Vcd6BRmD
5tvtPahihu
 
'''

 





answered Apr 13, 2021 by avibootz
0 votes
import string
import random
 
N = 5

for x in range(N):
    print(''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(20)))
 
  
  
  
'''
run:
  
Yjtr9sul3PkORIHTx2fw
2wZBgQHWlFJCl16RVhxC
Ppl4fbeesJ2DLmdmC739
7Y6SYiKxdywzePyvp78A
2l4DhHP68AbsxtMd8nI3
  
'''

 





answered Apr 13, 2021 by avibootz

Related questions

1 answer 75 views
1 answer 93 views
3 answers 98 views
...