Random String Generator

  • Share this:

Code introduction


Generate a random string of a specified length.


Technology Stack : random

Code Type : Function

Code Difficulty :


                
                    
import random

def generate_random_string(length=10):
    """
    Generate a random string of a given length.
    """
    letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    result_str = ''.join(random.choice(letters) for i in range(length))
    return result_str                
              
Tags: