C#随机生成18位身份证号码
2014-03-29 12:31
531 查看
In fact, the PIN code is just simple, but only with a checksum in the last char. With many guys asp/php and also js 's help, I get on my way!
http://blog.csdn.net/crabo/
private void GenPinCode()
{
System.Random rnd;
string[] _crabodistrict=new string[]{"350201","350202","350203","350204","350205","350206","350211","350205","350213"};
rnd = new Random(System.DateTime.Now.Millisecond);
//PIN = District + Year(50-92) + Month(01-12) + Date(01-30) + Seq(001-600)
string _pinCode=string.Format("{0}19{1}{2:00}{3:00}{4:000}",_crabodistrict[rnd.Next(0,8)],rnd.Next(50,92),rnd.Next(1,12),rnd.Next(1,30),rnd.Next(1,600));
#region Verify
char[] _chrPinCode = _pinCode.ToCharArray();
//校验码字符值
char[] _chrVerify=new char[]{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
//i----表示号码字符从由至左包括校验码在内的位置序号;
//ai----表示第i位置上的号码字符值;
//Wi----示第i位置上的加权因子,其数值依据公式intWeight=2(n-1)(mod 11)计算得出。
int[] _intWeight=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
int _craboWeight=0;
for(int i=0;i<17;i++)//从1 到 17 位,18为要生成的验证码
{
_craboWeight=_craboWeight+Convert.ToUInt16(_chrPinCode[i].ToString())*_intWeight[i];
}
_craboWeight=_craboWeight%11;
_pinCode+=_chrVerify[_craboWeight];
#endregion
this.txtPIN.Text=_pinCode;
}
http://blog.csdn.net/crabo/
private void GenPinCode()
{
System.Random rnd;
string[] _crabodistrict=new string[]{"350201","350202","350203","350204","350205","350206","350211","350205","350213"};
rnd = new Random(System.DateTime.Now.Millisecond);
//PIN = District + Year(50-92) + Month(01-12) + Date(01-30) + Seq(001-600)
string _pinCode=string.Format("{0}19{1}{2:00}{3:00}{4:000}",_crabodistrict[rnd.Next(0,8)],rnd.Next(50,92),rnd.Next(1,12),rnd.Next(1,30),rnd.Next(1,600));
#region Verify
char[] _chrPinCode = _pinCode.ToCharArray();
//校验码字符值
char[] _chrVerify=new char[]{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
//i----表示号码字符从由至左包括校验码在内的位置序号;
//ai----表示第i位置上的号码字符值;
//Wi----示第i位置上的加权因子,其数值依据公式intWeight=2(n-1)(mod 11)计算得出。
int[] _intWeight=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
int _craboWeight=0;
for(int i=0;i<17;i++)//从1 到 17 位,18为要生成的验证码
{
_craboWeight=_craboWeight+Convert.ToUInt16(_chrPinCode[i].ToString())*_intWeight[i];
}
_craboWeight=_craboWeight%11;
_pinCode+=_chrVerify[_craboWeight];
#endregion
this.txtPIN.Text=_pinCode;
}
相关文章推荐
- C# 随机生成手机号码(中国地区)
- Java 批量随机生成身份证号码(未测试)
- C#实现的18位身份证号码最新算法[验证部分]
- 请问在C#的Winform下如何用正则表达式限制用户只能在textBox中输入18位的身份证号码。
- 身份证号码15位升18位(C#)
- 身份证号码15位升18位(C#)
- EXCEL随机生成身份证号码
- 批量随机生成身份证号码
- Java随机生成18位身份证号
- 身份证号码查询与生成(C#源码)
- 使用C#实现身份证号码15位到18位的转换
- Python 随机生成有效手机号码及身份证
- Java 批量随机生成身份证号码
- 随机生成身份证号码
- 一个生成随机身份证号码的接口
- 身份证号码15位转18位 C#实现
- 自定义RFS关键字库中的关键字(使用python随机生成身份证号码)
- 用SQL 生成18位身份证号码
- 18位身份证号码校验和生成工具