Random String Generator

  • Share this:

Code introduction


This function generates a random string of specified length, consisting of lowercase letters and digits.


Technology Stack : string, random

Code Type : Generate random strings

Code Difficulty : Beginner


                
                    
import string
import random

def generate_random_string(length=10):
    return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))                
              
Tags: