You can download this code by clicking the button below.
This code is now available for download.
Generates a random string of a specified length composed of uppercase letters, lowercase letters, and digits.
Technology Stack : random
Code Type : Function
Code Difficulty : Intermediate
import random
def generate_random_string(length=10):
"""
Generate a random string of specified length using the letters and digits.
"""
letters_and_digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
result_str = ''.join(random.choice(letters_and_digits) for _ in range(length))
return result_str