Last active
March 6, 2021 03:04
-
-
Save Refffy/869d386d3814747dfceba9e443249f32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint, getrandbits | |
from typing import Dict, List, Tuple | |
from datetime import datetime | |
def is_leap(year: int) -> bool: | |
return False if year % 4 != 0 else( | |
True if year % 100 != 0 | |
else( | |
True if year % 400 == 0 | |
else False | |
) | |
) | |
def generate_iin() -> List[int]: | |
iin = [0 for i in range(12)] | |
curr_year = datetime.now().year | |
months: Dict[Tuple[str], str] = { | |
('02',): '28' if is_leap(curr_year) is False else '29', | |
('01', '03', '05', '07', '08', '10', '12'): '31', | |
('04', '06', '09', '11'): '30', | |
} | |
hash = getrandbits(3) | |
total_hash = (randint(1, 3) % hash if hash != 0 else randint( | |
1, 3)) // hash if hash != 0 else randint(1, 4) | |
year_x, year_y = randint(0, 9), randint(0, 9) | |
month_x = randint(0, 1) | |
month_y = randint(1, 9) if month_x != 1 else randint(0, 2) | |
mont_val = (month_x, month_y) | |
for k, v in months.items(): | |
if f'{mont_val[0]}{mont_val[1]}' in k: | |
day = str(randint(28, int(v))) | |
def total_iin() -> List[int]: | |
iin[0:2] = [year_x, year_y] | |
iin[2:4] = [month_x, month_y] | |
iin[4:6] = [int(day[0]), int(day[1])] | |
iin[6] = randint(3, 6) | |
# iin[7:11] = [randint(1, 5) for i in range(4)] | |
iin[7:11] = [ | |
( | |
total_hash if total_hash != 0 else randint(1, 3) | |
) for i in range(4) | |
] | |
twelve = sum(iin[i]*(i+1) for i in range(11)) % 11 | |
twelve_10 = ( | |
sum( | |
iin[0:11][i+1] * i for i in range(1, 10) | |
) + (10*iin[0]+11*iin[1]) | |
) % 11 | |
if twelve != 10: | |
iin[11] = twelve | |
elif twelve_10 != 10: | |
iin[11] = twelve_10 | |
else: | |
pass | |
return iin | |
return total_iin() | |
if __name__ == '__main__': | |
iin = ''.join(str(i) for i in generate_iin()) | |
print(iin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!