Random String Generator

  • Share this:

Code introduction


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))