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, composed of letters, digits, and special characters.
Technology Stack : math, random, string, datetime, re, json, os
Code Type : Function
Code Difficulty : Intermediate
import math
import random
import string
import datetime
import re
import json
import os
def generate_random_password(length=8):
if not isinstance(length, int) or length < 8:
raise ValueError("Password length must be an integer greater than or equal to 8.")
characters = string.ascii_letters + string.digits + "!@#$%^&*()_+-="
password = ''.join(random.choice(characters) for i in range(length))
return password