Random Password Generator

  • Share this:

Code introduction


Generates a random password of a specified length, consisting of letters and digits


Technology Stack : os, sys, random, string, datetime, math

Code Type : Function

Code Difficulty : Intermediate


                
                    
import os
import sys
import random
import string
import datetime
import math

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