You can download this code by clicking the button below.
This code is now available for download.
This function generates a random string of a specified length, including both uppercase and lowercase letters and numbers.
Technology Stack : random
Code Type : Generate random strings
Code Difficulty : Intermediate
def random_string(length, chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
import random
return ''.join(random.choice(chars) for _ in range(length))