I want to generate a 10 alphanumeric character long string in python . So here is one part of selecting random index from a list of alphanumeric chars.
My plan :
set_list = ['a','b','c' ........] # all the way till I finish [a-zA-Z0-9]
index = random() # will use python's random generator
some_char = setlist[index]
Is there a better way of choosing a character randomly ?
The usual way is random.choice()
>>> import string
>>> import random
>>> random.choice(string.ascii_letters + string.digits)
'v'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With