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 letters, digits, and special characters.
Technology Stack : os, re, json, time, math, random, string, sys
Code Type : Generate random password
Code Difficulty : Intermediate
import os
import re
import json
import time
import math
import random
import string
import sys
def generate_random_password(length=12):
if not isinstance(length, int) or length < 6:
raise ValueError("Length must be an integer greater than or equal to 6")
characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(characters) for i in range(length))