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