How to add random strings in py 3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to add random strings in py 3?

I’ve searched everything and everywhere on this app and I couldn’t find anything to give me the answer. Pls help!

7th May 2018, 10:36 AM
Maciek
Maciek - avatar
2 Answers
+ 3
"How to generate a random string: " https://www.pythoncentral.io/JUMP_LINK__&&__python__&&__JUMP_LINK-snippets-how-to-generate-random-string/ "Generating a random string." https://pythontips.com/2013/07/28/generating-a-random-string/amp/ A sample code: import random import string def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) print(random_string_generator()) print(random_string_generator(size=50)) Source: https://www.codingforentrepreneurs.com/blog/random-string-generator-in-python/
7th May 2018, 10:49 AM
Rahul George
Rahul George - avatar
+ 3
import string from random import choice rdstring = "".join(choice(string.ascii_letters) for x in range(10)) #gives a random 10-letter string of letters only
7th May 2018, 3:34 PM
Johannes
Johannes - avatar