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, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import os
import hashlib
import datetime
import re
import time
import smtplib
import socket
import json

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