Random Password Generator

  • Share this:

Code introduction


This function is used to generate a random password of a specified length, composed of uppercase and lowercase letters and numbers.


Technology Stack : os, re, json, sys, math, time, random, string, shutil

Code Type : Password generator

Code Difficulty : Intermediate


                
                    
import os
import re
import json
import sys
import math
import time
import random
import string
import shutil

def generate_random_password(length=12):
    if not isinstance(length, int) or length < 4:
        raise ValueError("Password length must be an integer greater than or equal to 4")
    
    characters = string.ascii_letters + string.digits
    return ''.join(random.choice(characters) for _ in range(length))