Random String Generator

  • Share this:

Code introduction


Generate a random string of a specified length.


Technology Stack : random, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import string

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