Random String Generator

  • Share this:

Code introduction


This function generates a random string of a specified length, which can include both uppercase and lowercase letters and digits.


Technology Stack : random, string

Code Type : String generation

Code Difficulty : Beginner


                
                    
import random
import string

def generate_random_string(length, characters=string.ascii_letters + string.digits):
    return ''.join(random.choice(characters) for _ in range(length))                
              
Tags: