def ssn(
        self,
        min_age: int = 18,
        max_age: int = 90,
        long: bool = False,
        dash: bool = True,
    ) -> str:
        """
        Returns a 10 or 12 (long=True) digit Swedish SSN, "Personnummer".

        It consists of 10 digits in the form (CC)YYMMDD-SSSQ, where
        YYMMDD is the date of birth, SSS is a serial number
        and Q is a control character (Luhn checksum).

        Specifying dash=False will give a purely numeric string, suitable
        for writing direct to databases.

        http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
        """

        age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))
        birthday = datetime.datetime.now() - age
        yr_fmt = "%Y" if long else "%y"
        pnr_date = f"{birthday:{yr_fmt}%m%d}"
        chk_date = pnr_date[2:] if long else pnr_date
        suffix = f"{self.generator.random.randrange(0, 999):03}"
        luhn_checksum = str(calculate_luhn(int(chk_date + suffix)))
        hyphen = "-" if dash else ""
        pnr = f"{pnr_date}{hyphen}{suffix}{luhn_checksum}"

        return pnr

        Returns a 10 or 12 (long=True) digit Swedish SSN, "Personnummer".

        It consists of 10 digits in the form (CC)YYMMDD-SSSQ, where
        YYMMDD is the date of birth, SSS is a serial number
        and Q is a control character (Luhn checksum).

        Specifying dash=False will give a purely numeric string, suitable
        for writing direct to databases.

        http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
        
faker/providers/ssn/sv_SE/__init__.py