Random String Generator

  • Share this:

Code introduction


This function generates a random string of a specified length using a set of characters that includes both letters and digits.


Technology Stack : random, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import math
import string
import json
import os
import shutil
import datetime
import hashlib
import re

def generate_random_string(length, characters=string.ascii_letters + string.digits):
    """Generate a random string of a specified length using a set of characters."""
    return ''.join(random.choice(characters) for i in range(length))                
              
Tags: