Generating a random date string prefix

private static final String CHAR_SET 

= "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789";

private static final Integer SUFFIX_LENGTH = 10;

public static String generateRequestID() {

Pattern = String "yyyyMMddHHmmssSSS";
the SimpleDateFormat the dateFormat the SimpleDateFormat new new = (pattern);
String CurDate = dateFormat.format (new new a Date ());
String suffix = generateRandomSuffix (); // generated random strings to date format the return curDate suffix +; } // SUFFIX_LENGTH bit random string generated in CHAR_SET Private generateRandomSuffix static string () { the StringBuilder suffixBuilder the StringBuilder new new = (); int NUM = CHAR_SET.length (); the random random the random new new = (NUM); for ( 0 = I int; I <SUFFIX_LENGTH; I ++) { int J = random.nextInt (NUM); char CHAR_SET.charAt = C (J); suffixBuilder.append (C); } return suffixBuilder.toString (); }















Guess you like

Origin blog.csdn.net/John_Kry/article/details/79410203