+ 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!
2 odpowiedzi
+ 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/
+ 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