Random String Generator

  • Share this:

Code introduction


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


Technology Stack : random

Code Type : Generate random strings

Code Difficulty : Intermediate


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