Generate Random String using Python

random.choices & join functions

import random


def generateRandomString(length):
    chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

    return ''.join(random.choices(chars, k=length))


randomString = generateRandomString(10)
print(randomString)

Leave a Comment

Cancel reply

Your email address will not be published.