//
// 20201205153600
//
// 3591.411717413242
//
//
// 202012051536003591
//
public static String getRandom() {
String result = "";//定义接收对象
//引用时间方法
result += TimeFormat("yyyyMMddHHmmss");
//调用数学函数生成一个随机数
Double rand = Math.random() * 10000;
if (rand < 10) {//因为是随机数 如果说随机数小于 10 会截取索引0到1 的值 (索引是从零开始的)
result += "000" + rand.toString().substring(0, 1);//如果是1位的话 怎么三个000拼接成功4位
} else if (rand < 100) {
result += "00" + rand.toString().substring(0, 2);/如果是2位的话 怎么三个00拼接成功4位
} else if (rand < 1000) {
result += "0" + rand.toString().substring(0, 3);/如果是3位的话 怎么三个0拼接成功4位
} else {
result += rand.toString().substring(0, 4);
}
// LOG.info(“18位数====={}”, result);
return result;
}
//生成当前时间
public static String TimeFormat(String timeType){
SimpleDateFormat simpleDateFormat new SimpleDateFormat(timeType);
String nowTime= simpleDateFormat.format(new Date());
return nowTime;
}