首页 技术 正文
技术 2022年11月6日
0 收藏 353 点赞 744 浏览 1671 个字
package com.ihome.data;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.Random;public class CertNoUtil {    // 18位身份证号码各位的含义:    // 1-2位省、自治区、直辖市代码;    // 3-4位地级市、盟、自治州代码;    // 5-6位县、县级市、区代码;    // 7-14位出生年月日,比如19670401代表1967年4月1日;    // 15-17位为顺序号,其中17位(倒数第二位)男为单数,女为双数;    // 18位为校验码,0-9和X。    // 作为尾号的校验码,是由把前十七位数字带入统一的公式计算出来的,    // 计算的结果是0-10,如果某人的尾号是0-9,都不会出现X,但如果尾号是10,那么就得用X来代替,    // 因为如果用10做尾号,那么此人的身份证就变成了19位。X是罗马数字的10,用X来代替10    public static String getRandomID() {        String id = "";        // 随机生成省、自治区、直辖市代码 1-2        String provinces[] = { "11", "12", "13", "14", "15", "21", "22", "23",                "31", "32", "33", "34", "35", "36", "37", "41", "42", "43",                "44", "45", "46", "50", "51", "52", "53", "54", "61", "62",                "63", "64", "65", "71", "81", "82" };        String province = provinces[new Random().nextInt(provinces.length - 1)];        // 随机生成地级市、盟、自治州代码 3-4        String citys[] = { "01", "02", "03", "04", "05", "06", "07", "08",                "09", "10", "21", "22", "23", "24", "25", "26", "27", "28" };        String city = citys[new Random().nextInt(citys.length - 1)];        // 随机生成县、县级市、区代码 5-6        String countys[] = { "01", "02", "03", "04", "05", "06", "07", "08",                "09", "10", "21", "22", "23", "24", "25", "26", "27", "28",                "29", "30", "31", "32", "33", "34", "35", "36", "37", "38" };        String county = countys[new Random().nextInt(countys.length - 1)];        // 随机生成出生年月 7-14        SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");        Date beginDate = new Date();        Calendar date = Calendar.getInstance();        date.setTime(beginDate);        date.set(Calendar.DATE,                date.get(Calendar.DATE) - new Random().nextInt(365 * 100));        String birth = dft.format(date.getTime());        // 随机生成顺序号 15-17        String no = new Random().nextInt(999) + "";        // 随机生成校验码 18        String checks[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",                "X" };        String check = checks[new Random().nextInt(checks.length - 1)];        // 拼接身份证号码        id = province + city + county + birth + no + check;        return id;    }}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289