Random Password Generator

  • Share this:

Code introduction


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


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

Code Type : Function

Code Difficulty : Intermediate


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

def generate_random_password(length=8):
    if length < 8:
        length = 8
    characters = string.ascii_letters + string.digits
    return ''.join(random.choice(characters) for _ in range(length))