1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
const IDCard = { aProvince : [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 ], aCity : ['0101', '0201'], sId : '', iBirDate : '', repTimes : 50, getRandom(iMin,iMax){ return Math.round(Math.random()*(iMax-iMin))+iMin; }, addZero(str,num){ str=str.toString(); for(let i=0,len=num-str.length;i<len;i++){ str=`0${str}`; } return str; }, init(){ return this.toId(); }, toProvince(){ return this.aProvince[ this.getRandom(0 , this.aProvince.length-1)]; }, toCity(){ return this.aCity[ this.getRandom(0 , this.aCity.length - 1)]; }, toBirthday(){ let ia=new Date(); let start = new Date() - 50*365*24*60*60*1000; let end = new Date() - 18*365*24*60*60*1000; let ageDate = this.getRandom( start , end ); ia.setTime( ageDate ); return ia.getFullYear() + '' + this.addZero( ia.getMonth() + 1 , 2 ) + this.addZero( ia.getDate() , 2 ); }, toLast (){ let arrLastFour = []; for(let i=0; i<4; i++){ arrLastFour.push(this.getRandom(0,9)); } return arrLastFour.join(''); }, toId(){ for( let j=0; j <50 ; j++){ this.sId = '' + this.toProvince() +''+ this.toCity() + this.toBirthday() + this.toLast(); let iSum = 0; for (let i = 17; i >= 0; i--) { iSum += (Math.pow(2, i) % 11) * parseInt(this.sId.charAt(17 - i), 11); } if (iSum % 11 == 1) { console && console.log(this.sId +' //////// ' +j); return this.sId; } } }, };
|