Random String Generator

  • Share this:

Code introduction


Generate a random string of a specified length.


Technology Stack : random, string operations

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def generate_random_string(length=10):
    """
    Generate a random string of specified length.
    """
    letters = 'abcdefghijklmnopqrstuvwxyz'
    result_str = ''.join(random.choice(letters) for i in range(length))
    return result_str