You can use Python random and string module to generate a random string with uppercase, lowercase, number, and special characters of a certain length. This can also be used as Python random password generator as shown in the below example –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import random import string ## Length of the string length = 12 lower = string.ascii_lowercase upper = string.ascii_uppercase num = string.digits symbols = string.punctuation all = lower + upper + num + symbols temp = random.sample(all,length) randstr = "".join(temp) print(randstr) |