Random String Generator

  • Share this:

Code introduction


This function generates a random string of a specified length using the 'random' built-in module.


Technology Stack : random

Code Type : String generation

Code Difficulty :


                
                    
import random

def generate_random_string(length):
    """
    Generate a random string of given length using the 'random' module.
    """
    letters = 'abcdefghijklmnopqrstuvwxyz'
    result_str = ''.join(random.choice(letters) for i in range(length))
    return result_str                
              
Tags: