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