Random String Generator

  • Share this:

Code introduction


Generates a random string of a specified length, with characters being letters and digits.


Technology Stack : random, string

Code Type : String generation

Code Difficulty : Beginner


                
                    
import random
import string

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