/** 1. * 动态生成16位不重复随机数 * * @return */ public synchronized static String generate16() { StringBuffer stringBuffer = new StringBuffer(); String date = DatetimeUtil.getDateyyyyMMddNone(); String seconds = DatetimeUtil.getDateHHmmssNone(); stringBuffer.append(date).append(generate2()).append(seconds); return stringBuffer.toString(); } public static String getDateyyyyMMddNone() { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String fd = sdf.format(date); return fd; } public static String getDateHHmmssNone() { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("HHmmss"); String fd = sdf.format(date); return fd; } 2. /** * 随机创建2位ID * * @return String 2位随机数ID */ public synchronized static String generate2() { Random rad = new Random(); String result = rad.nextInt(100) + ""; if (result.length() == 1) { result = "0" + result; } return result; }