随机生成身份证号和年龄
2015-06-14 21:23
302 查看
package main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class demo {
public static void main(String argv[]) throws IOException {
if (argv.length < 1) {
System.err.println("Parameter missing.");
System.err.println("Usage: input:recall-list;output:rank-list");
return;
}
// Initial
String input = argv[1];
// Input
File file = new File(input);
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "gbk"));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(file+"result"), "gbk"), true);
String line = null;
while ((line = br.readLine()) != null) {
String[] seg = line.split("\t");
String id = "";
// 随机生成省、自治区、直辖市代码 1-2
String provinces[] = { "50" ,"50", "50"};
String province = provinces[new Random()
.nextInt(provinces.length - 1)];
// 随机生成地级市、盟、自治州代码 3-4
String citys[] = { "01", "02" };
String city = citys[new Random().nextInt(citys.length - 1)];
// 随机生成县、县级市、区代码 5-6
String countys[] = { "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "41",
"42", "43", "40", };
String county = countys[new Random().nextInt(countys.length - 1)];
// String nannv = seg[8];
Random rand = new Random();
int nanv = rand.nextInt(1);
if (nanv == 1) {
seg[8] = "男";
} else {
seg[8] = "女";
}
// 随机生成出生年月 7-14
SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat dft2 = new SimpleDateFormat("yyyy");
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());
String birth2 = dft2.format(date.getTime());
seg[9] = String.valueOf(2015 - Integer.parseInt(birth2));
// 随机生成顺序号 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;
seg[10] = id;
System.out.println(line);
for (int i = 0; i < seg.length; i++) {
pw.print(seg[i] + "\t");
}
pw.print("\n");
}
br.close();
pw.close();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class demo {
public static void main(String argv[]) throws IOException {
if (argv.length < 1) {
System.err.println("Parameter missing.");
System.err.println("Usage: input:recall-list;output:rank-list");
return;
}
// Initial
String input = argv[1];
// Input
File file = new File(input);
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "gbk"));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(file+"result"), "gbk"), true);
String line = null;
while ((line = br.readLine()) != null) {
String[] seg = line.split("\t");
String id = "";
// 随机生成省、自治区、直辖市代码 1-2
String provinces[] = { "50" ,"50", "50"};
String province = provinces[new Random()
.nextInt(provinces.length - 1)];
// 随机生成地级市、盟、自治州代码 3-4
String citys[] = { "01", "02" };
String city = citys[new Random().nextInt(citys.length - 1)];
// 随机生成县、县级市、区代码 5-6
String countys[] = { "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "13", "14", "15", "16", "17",
"18", "19", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "41",
"42", "43", "40", };
String county = countys[new Random().nextInt(countys.length - 1)];
// String nannv = seg[8];
Random rand = new Random();
int nanv = rand.nextInt(1);
if (nanv == 1) {
seg[8] = "男";
} else {
seg[8] = "女";
}
// 随机生成出生年月 7-14
SimpleDateFormat dft = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat dft2 = new SimpleDateFormat("yyyy");
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());
String birth2 = dft2.format(date.getTime());
seg[9] = String.valueOf(2015 - Integer.parseInt(birth2));
// 随机生成顺序号 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;
seg[10] = id;
System.out.println(line);
for (int i = 0; i < seg.length; i++) {
pw.print(seg[i] + "\t");
}
pw.print("\n");
}
br.close();
pw.close();
}
}
相关文章推荐
- 宿舍打分系统代码更新的操作
- EasyUi datagrid window
- 对开发者有益的网站
- 数字签名是什么?
- Note_iOS系统架构
- Android学习6.1下拉列表一
- 重拾信心,一路向前
- 好代码片段让网站在搜索结果中具有好的结果
- Word 取消超链接快捷键
- 算法练习:产生指定范围的随机数
- 【iOS开发-网络】AFN的使用
- Python_Scrapy_5.类的学习
- 关于出现 ArrayAdapter requires the resource ID to be a TextView问题
- The YubiKey NEO
- c++ list
- hdu 2563 统计问题
- 统计学习第一发
- Aggregate
- opencv和pcl的flann冲突的解决
- ConcurrentHashMap原理分析