You can download this code by clicking the button below.
This code is now available for download.
This function generates a random password of specified length, consisting of both uppercase and lowercase letters and digits.
Technology Stack : os, json, re, random, string, sys
Code Type : Generate random password
Code Difficulty : Intermediate
import os
import json
import re
import random
import string
import sys
def generate_random_password(length=8):
if not isinstance(length, int) or length < 1:
raise ValueError("Password length must be a positive integer.")
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for i in range(length))