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 using the built-in string and random libraries.
Technology Stack : Built-in string library (string), random library (random)
Code Type : Function
Code Difficulty : Intermediate
import random
import string
import math
import datetime
import os
import sys
import re
def generate_random_string(length):
"""
Generate a random string of given length using built-in string library.
Args:
length (int): The length of the random string to generate.
Returns:
str: A random string of the specified length.
"""
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))