Random String Generator

  • Share this:

Code introduction


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


Technology Stack : Packages and technologies used in the code

Code Type : Function

Code Difficulty : Beginner


                
                    
import math
import os
import random
import re
import shutil
import socket
import sys
import time

def generate_random_string(length, characters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
    return ''.join(random.choice(characters) for i in range(length))