1 import java.text.DecimalFormat 2 import java.text.SimpleDateFormat 3 import java.util.Calendar; 4 import java.util.Collection; 5 import java.util.HashMap; 6 import java.util.Iterator; 7 import java.util.Map; 8 import java.util.stream.LongStream 9 10 11 def get_random_area_code() { 12 int[] areaCode =[110000,110100,110101,110102,110103,110104,110105,110106,110107,110108,110109,110111,110112,110113,110114,110115,110116,110117,110200,110228,110229,120000,120100,120101,120102,120103,120104,120105,120106,120110,120111,120112,120113,120114,120115,120200,120221,120223,120225,130000,130100,130101,130102,130103,130104,130105,130107,130108,130121,130123,130124,130125,130126,130127,130128,130129,130130,130131,130132,130133,130181,130182,130183,130184,130185,130200,130201,130202,130203,130204,130205,130207,130208,130223,130224,130225,130227,130229,130230,130281,130283,130300,130301,130302,130303,130304,130321,130322,130323,130324,130400,130401,130402,130403,130404,130406,130421,130423,130424,130425,130426,130427,130428,130429,130430,130431,130432,130433,130434,130435,130481,130500,130501,130502,130503,130521,130522,130523,130524,130525,130526,130527,130528,130529,130530,130531,130532,130533,130534,130535,130581,130582,130600,130601,130602,130603,130604,130621,130622,130623,130624,130625,130626,130627,130628,130629,130630,130631,130632,130633,130634,130635,130636,130637,130638,130681,130682,130683,130684,130700,130701,130702,130703,130705,130706,130721,130722,130723,130724,130725,130726,130727,130728,130729,130730,130731,130732,130733,130800,130801,130802,130803]; 13 return areaCode[(int)(Math.random() * areaCode.size())].toString(); 14 } 15 16 def get_random_birthday() { 17 Calendar birthday = Calendar.getInstance(); 18 birthday.add(Calendar.YEAR, -20); 19 birthday20 = birthday.getTimeInMillis(); 20 randomTimeStamp = (long)( Math.random()* birthday20) ; 21 // println(birthday20); 22 // println(randomTimeStamp); 23 24 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd") ; 25 birthday_between_1970_and_20yearsAgo = sdf.format(new Date(randomTimeStamp)); 26 // println(birthday_between_1970_and_20yearsAgo); 27 return birthday_between_1970_and_20yearsAgo; 28 } 29 30 def get_random_num() { 31 DecimalFormat df = new DecimalFormat("000"); 32 return df.format((long)(Math.random() * 1000)); 33 } 34 35 def get_last_num(char[] chars) { 36 if (chars.length < 17) { 37 return ' '; 38 } 39 int[] c = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]; 40 char[] r = [ '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' ]; 41 int[] n = new int[17]; 42 int result = 0; 43 for (int i = 0; i < n.length; i++) { 44 n[i] = Integer.parseInt(chars[i].toString() ); 45 } 46 for (int i = 0; i < n.length; i++) { 47 result += c[i] * n[i]; 48 } 49 return r[result % 11]; 50 } 51 52 def get_id_no() { 53 area_code = get_random_area_code(); 54 birthday = get_random_birthday(); 55 random_num = get_random_num(); 56 idnum17 = area_code + birthday +random_num ; 57 last_num = get_last_num(idnum17.toCharArray()); 58 // println(idnum17); 59 // println(last_num); 60 return idnum17 + last_num; 61 } 62 OUT.println(get_id_no());