"""Random password generator."""

import random
import string


def password_generator():
    """
    Generates a secure password with uppercase, lowercase, numbers, and special characters.

    Returns:
      A string containing the randomly generated password.
    """

    chars = string.ascii_letters + string.digits + string.punctuation

    password = ""
    while len(password) < 8:
        if len(password) == 0:
            chars: str = string.ascii_letters
            char: str = random.choice(chars)
            char = char.upper()
        elif len(password) == 7:
            chars: str = string.punctuation
            char: str = random.choice(chars)

        else:
            char: str = random.choice(chars)
        password += char

    return password
