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, composed of uppercase and lowercase letters and digits.
Technology Stack : Python built-in libraries
Code Type : Function
Code Difficulty : Intermediate
import datetime
import os
import re
import string
def generate_random_string(length):
if not isinstance(length, int) or length <= 0:
raise ValueError("Length must be a positive integer")
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(length))