Random String Generator

  • Share this:

Code introduction


Generates a random string of specified length containing uppercase and lowercase letters and numbers.


Technology Stack : random, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_string(length, allowed_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"):
    import random
    import string
    return ''.join(random.choice(allowed_chars) for _ in range(length))                
              
Tags: