Created
January 29, 2024 07:49
-
-
Save mypapit/1de18b6b94fcc51bfea19a418a501069 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import random | |
| #this is to generate fake mykad numbers | |
| def generate_mykad_number(): | |
| # Generate date of birth (YYMMDD) | |
| year = str(random.randint(50, 99)) # assuming a range for adult ages | |
| month = str(random.randint(1, 12)).zfill(2) | |
| day = str(random.randint(1, 28)).zfill(2) # using 28 to avoid issues with February | |
| dob = year + month + day | |
| # Generate birthplace code (PB) | |
| birthplace = str(random.randint(1, 16)).zfill(2) # 01 to 16 for Malaysian states | |
| # Generate unique identifier (###) | |
| unique_id = str(random.randint(1, 999)).zfill(3) | |
| # Generate gender digit (G), odd for male and even for female | |
| gender_digit = str(random.randint(0, 9)) | |
| if int(unique_id) <= 499: # Male | |
| gender_digit = str(int(gender_digit) * 2 + 1)[-1] # ensure odd | |
| else: # Female | |
| gender_digit = str(int(gender_digit) * 2)[-1] # ensure even | |
| return dob + '-' + birthplace + '-' + unique_id + gender_digit | |
| # Generate 10 fake MyKad numbers | |
| fake_mykad_numbers = [generate_mykad_number() for _ in range(10)] | |
| fake_mykad_numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment