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 using the built-in `random` module.
Technology Stack : random
Code Type : Function
Code Difficulty : Beginner
import random
def generate_random_string(length):
"""
Generate a random string of a given length using the `random` module.
:param length: The length of the random string to generate.
:return: A random string of the specified length.
"""
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
return ''.join(random.choice(letters) for i in range(length))