Python 随机生成有效手机号码及身份证
中国那么大,人那么多,几乎人手一部手机。手机号码已经作为各大互联网站的注册账户。同样,身份证更是如此。以下是生成有效手机号码和身份证号。
身份证需要下载districtcode.txt这个文件:http://files.cnblogs.com/files/yicaifeitian/districtcode.rar
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DC_PATH = BASE_DIR + "districtcode.txt"
# 随机生成手机号码
def createPhone():
prelist=["]
") for i in range(8))
# 随机生成身份证号
def getdistrictcode():
with open(DC_PATH) as file:
data = file.read()
districtlist = data.split('\n')
for node in districtlist:
#print node
if node[10:11] != ' ':
state = node[10:].strip()
if node[10:11]==' 'and node[12:13]!=' ':
city = node[12:].strip()
if node[10:11] == ' 'and node[12:13]==' ':
district = node[14:].strip()
code = node[0:6]
codelist.append({"state":state,"city":city,"district":district,"code":code})
def gennerator():
global codelist
codelist = []
if not codelist:
getdistrictcode()
id = codelist[random.randint(0,len(codelist))]['code'] #地区项
id = id + str(random.randint(1930,2013)) #年份项
da = date.today()+timedelta(days=random.randint(1,366)) #月份和日期项
id = id + da.strftime('%m%d')
id = id+ str(random.randint(100,300))#,顺序号简单处理
i = 0
count = 0
weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] #权重项
checkcode ={'} #校验码映射
for i in range(0,len(id)):
count = count +int(id[i])*weight[i]
id = id + checkcode[str(count%11)] #算出校验码
return id
print createPhone()
print gennerator()
Python 随机生成有效手机号码及身份证的更多相关文章
- python随机生成个人信息
python随机生成个人信息 #!/usr/bin/env python3 # -*- coding:utf-8 -*- import sys import random class Personal ...
- Python随机生成验证码的两种方法
Python随机生成验证码的方法有很多,今天给大家列举两种,大家也可以在这个基础上进行改造,设计出适合自己的验证码方法方法一:利用range Python随机生成验证码的方法有很多,今天给大家列举两种 ...
- 用python随机生成数据,再插入到postgresql中
用python随机生成学生姓名,三科成绩和班级数据,再插入到postgresql中. 模块用psycopg2 random import random import psycopg2 fname=[' ...
- python随机生成手机号码
一句话生成电话号码random.choice(['139','188','185','136','158','151'])+"".join(random.choice(" ...
- python 随机生成固定长度的字串
from random import Random#随机生成4到20位的用户名def random_username(): username = '' chars = 'AaBbCcDdEeFfGgH ...
- python随机生成6位数验证码
#随机生成6位数验证码 import randomcode = []for i in range(6): if i == str(random.randint(1,5)): cod ...
- python随机生成库faker库api详解
# -*- coding: utf-8 -*- # @Author : FELIX # @Date : 2018/6/30 9:49 from faker import Factory # zh_CN ...
- python随机生成字符
Python2: Unicode是一种通用的编码方式,不论是英文字母.汉字.日语还是其他文字都能够对应一个唯一的Unicode编码(序号). chr(100) # 得到整数对应的ascii码(小于25 ...
- python 随机生成用户名、密码、手机号码
#!C:\Python #!/usr/bin/env python #-*- coding:utf-8 -*- import string import random minlength = 6 ma ...
随机推荐
- CSS3 转换、过渡和动画
一.转换 1.属性:transform 取值:none/transform-function(转换函数) 注意:如果要实现多个转换函数的话,可以用空格分开若干transform-function 2. ...
- 4月6日--js生成随机数列
newarr=[1,2,3,4,5,6] function randomsort(a,b){ return Math.random()>0.5?-1:1;}//用Math.random()函数生 ...
- 鼠标滚动:mousewheel事件在Firefox采用DOMMouseScroll事件的统一处理
这是一个小事件,但当下的WEB应用交互非常丰富,判断鼠标的滚动来执行相应的操作是比较常见的.我用Chrome/IE/Firefox/Opera 4种浏览器做测试,发现只有firefox的处理方法有很大 ...
- iOS各框架功能简述以及系统层次结构简单分析
iOS各个框架所对应的功能简单介绍 iOS系统结构层次:
- ios 视频拼接/合成
上面的图说明的是这个混合的过程,下面放代码: - (void)mergeAndExportVideos:(NSArray*)videosPathArray withOutPath:(NSString* ...
- HTTP上传 文件上传 图片上传 HTTP上传原理 文件上传原理 图片上传原理
1.概述 在最初的http协议中,没有上传文件方面的功能.rfc1867(http://www.ietf.org/rfc/rfc1867.txt )为http协议添加了这个功能.浏览器按照此规范将用户 ...
- css过渡模块和2d转换模块
今天,我们一起来研究一下css3中的过渡模块.2d转换模块和3d转换模块 一.过渡模块transition (一)过度模块的三要素: 1.必须要有属性发生变化 2.必须告诉系统哪个属性需要执行过渡效果 ...
- Redisson入门
Redisson入门 Author:Ricky Date:2017-04-24 Redisson概述 Redisson是架设在Redis基础上的一个Java驻内存数据网格(In-Memory Dat ...
- 实体框架(Entity Framework)
实体框架(Entity Framework) 实体框架(Entity Framework)简介 ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对 ...
- css优先级之特殊性
在前端开发的时候,css构建样式规则,这个时候我们会遇到一个问题:当我们对同一个元素做多个样式规则,其中发生了冲突的时候,css是如何选择最终呈现的样式 如下: div{ color:red; } d ...