Python generates random strings
There are two ways to generates random strings. The first one is to list all letters and numbers, and use random
package.
import random
base_str ='ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
p = random.sample(base_str, 5)
print(p)
>>>['S','P','G','Z','A']
The second method is to use string
package directly.
import string
value = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print(value)
>>>PpvgJLmS
0 人喜欢
There is no comment, let's add the first one.