You can download this code by clicking the button below.
This code is now available for download.
This function is used to generate a random password of a specified length, consisting of letters, digits, and special characters.
Technology Stack : string, random, string.punctuation
Code Type : Function
Code Difficulty : Intermediate
import random
import string
import re
import math
import datetime
import os
import sys
import time
import threading
def generate_random_password(length=12):
if length < 4:
raise ValueError("Password length must be at least 4 characters.")
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for i in range(length))
return password