Random String Generator

  • Share this:

Code introduction


This function generates a random string of a specified length using a set of characters which includes both uppercase and lowercase letters and numbers.


Technology Stack : Python, random

Code Type : Python Function

Code Difficulty : Intermediate


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