You can download this code by clicking the button below.
This code is now available for download.
Generate a random string of a specified length, which is commonly used in scenarios such as password generation and captcha generation.
Technology Stack : datetime, random, string
Code Type : String generation
Code Difficulty : Intermediate
import datetime
import random
import string
def generate_random_string(length):
"""
Generate a random string of a given length.
"""
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))