Random String Generator

  • Share this:

Code introduction


This function generates a random string of specified length, including uppercase and lowercase letters and numbers.


Technology Stack : random, string

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
def random_string_generator(length, characters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
    import random
    import string
    
    return ''.join(random.choice(characters) for i in range(length))                
              
Tags: