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, including uppercase and lowercase letters, digits, and special characters.
Technology Stack : os, json, re, sys, time, random, string, math
Code Type : Function
Code Difficulty : Intermediate
import os
import json
import re
import sys
import time
import random
import string
import math
def generate_random_password(length=12):
if length < 8:
raise ValueError("Password length should be at least 8 characters.")
letters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(letters) for i in range(length))
return password