def ssn(cls): """ Returns 11 character Estonian personal identity code (isikukood, IK). Age of person is between 16 and 90 years, based on local computer date. This function assigns random sex to person. An Estonian Personal identification code consists of 11 digits, generally given without any whitespace or other delimiters. The form is GYYMMDDSSSC, where G shows sex and century of birth (odd number male, even number female, 1-2 19th century, 3-4 20th century, 5-6 21st century), SSS is a serial number separating persons born on the same date and C a checksum. https://en.wikipedia.org/wiki/National_identification_number#Estonia """ age = datetime.timedelta( days=random.randrange(Provider.min_age, Provider.max_age)) birthday = datetime.date.today() - age if birthday.year < 2000: ik = random.choice(('3', '4')) elif birthday.year < 2100: ik = random.choice(('5', '6')) else: ik = random.choice(('7', '8')) ik += "%02d%02d%02d" % ( (birthday.year % 100), birthday.month, birthday.day) ik += str(random.randrange(0, 999)).zfill(3) return ik + str(checksum([int(ch) for ch in ik]))
def ssn(cls): """ Returns 11 character Estonian personal identity code (isikukood, IK). Age of person is between 16 and 90 years, based on local computer date. This function assigns random sex to person. An Estonian Personal identification code consists of 11 digits, generally given without any whitespace or other delimiters. The form is GYYMMDDSSSC, where G shows sex and century of birth (odd number male, even number female, 1-2 19th century, 3-4 20th century, 5-6 21st century), SSS is a serial number separating persons born on the same date and C a checksum. https://en.wikipedia.org/wiki/National_identification_number#Estonia """ age = datetime.timedelta(days=random.randrange(Provider.min_age, Provider.max_age)) birthday = datetime.date.today() - age if birthday.year < 2000: ik = random.choice(('3', '4')) elif birthday.year < 2100: ik = random.choice(('5', '6')) else: ik = random.choice(('7', '8')) ik += "%02d%02d%02d" % ((birthday.year % 100), birthday.month, birthday.day) ik += str(random.randrange(0, 999)).zfill(3) return ik + str(checksum([int(ch) for ch in ik]))
def ssn(cls): """ Returns 11 character Finnish personal identity code (Henkilötunnus, HETU, Swedish: Personbeteckning). Age of person is between 18 and 90 years, based on local computer date. This function assigns random sex to person. HETU consists of eleven characters of the form DDMMYYCZZZQ, where DDMMYY is the date of birth, C the century sign, ZZZ the individual number and Q the control character (checksum). The sign for the century is either + (1800–1899), - (1900–1999), or A (2000–2099). The individual number ZZZ is odd for males and even for females. For people born in Finland its range is 002-899 (larger numbers may be used in special cases). An example of a valid code is 311280-888Y. https://en.wikipedia.org/wiki/National_identification_number#Finland """ def _checksum(hetu): checksum_characters = "0123456789ABCDEFHJKLMNPRSTUVWXY" return checksum_characters[int(hetu) % 31] min_age = 18 * 365 max_age = 90 * 365 age = datetime.timedelta(days=random.randrange(min_age, max_age)) birthday = datetime.date.today() - age hetu_date = "%02d%02d%s" % (birthday.day, birthday.month, str(birthday.year)[-2:]) if birthday.year < 2000: separator = '-' else: separator = 'A' suffix = str(random.randrange(2, 899)).zfill(3) checksum = _checksum(hetu_date + suffix) hetu = "".join([hetu_date, separator, suffix, checksum]) return hetu
def binary(cls, length=(1 * 1024 * 1024)): """ Returns random binary blob. Default blob size is 1 Mb. """ blob = [random.randrange(256) for o in range(length)] return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)
def ssn(cls): """ Returns a 10 digit Swedish SSN, "Personnummer". It consists of 10 digits in the form YYMMDD-SSGQ, where YYMMDD is the date of birth, SSS is a serial number and Q is a control character (Luhn checksum). http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden) """ def _luhn_checksum(number): def digits_of(n): return [int(d) for d in str(n)] digits = digits_of(number) odd_digits = digits[-1::-2] even_digits = digits[-2::-2] checksum = 0 checksum += sum(odd_digits) for d in even_digits: checksum += sum(digits_of(d * 2)) return checksum % 10 def _calculate_luhn(partial_number): check_digit = _luhn_checksum(int(partial_number) * 10) return check_digit if check_digit == 0 else 10 - check_digit min_age = 18 * 365 max_age = 90 * 365 age = datetime.timedelta(days=random.randrange(min_age, max_age)) birthday = datetime.datetime.now() - age pnr_date = birthday.strftime('%y%m%d') suffix = str(random.randrange(0, 999)).zfill(3) luhn_checksum = str(_calculate_luhn(pnr_date + suffix)) pnr = '{0}-{1}{2}'.format(pnr_date, suffix, luhn_checksum) return pnr
def packet(self): l_data = random.randrange(200, 600) data = bytes(random.randrange(1 << 8) for i in range(l_data)) addr = fake.ipv4(), self.port() return self.timestamp(), addr, data
def port(self): return random.randrange(1 << 16)