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.
Technology Stack : os, random, string, sys, time
Code Type : Function
Code Difficulty : Intermediate
import os
import random
import string
import sys
import time
def random_string(length=10):
"""Generate a random string of fixed length.
Args:
length (int): The length of the string to generate.
Returns:
str: A random string of specified length.
"""
letters = string.ascii_letters + string.digits
return ''.join(random.choice(letters) for i in range(length))