Random Password Generator

  • Share this:

Code introduction


Generates a random password of a specified length, composed of uppercase and lowercase letters and digits.


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

Code Type : Function

Code Difficulty : Intermediate


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

def generate_random_password(length):
    if not isinstance(length, int) or length <= 0:
        raise ValueError("Password length must be a positive integer")
    return ''.join(random.choices(string.ascii_letters + string.digits, k=length))