createIdNum.py
753 Bytes
#coding=utf-8
# @Time : 2021/5/26 11:19
# @Author : Ljq
# @File : createIdNum.py
# @Software: PyCharm
"""
生成身份证号
"""
import time
import random
def cIN():
"""
身份证号生成
:return:
"""
# 拼接备用身份证号
area,birthday,policeStationCode,sex = 110101,time.strftime("%Y%m%d", time.localtime()),random.randint(10,99),random.randint(0,9)
idNum_str = f"{area}{birthday}{policeStationCode}{sex}"
basecCode = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
checkCode = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]
num = 0
for i in range(17):
num = num + basecCode[i] * int(idNum_str[i])
return f"{idNum_str}{checkCode[num % 11]}"
#
# print(cIN())