Random String Generator

  • Share this:

Code introduction


Generate a random string of a specified length and character set.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


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