CommonUtil { public static String getRandomChar(final int size) { StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < size; i++) { switch (random.nextInt(NEXT_INT) % NEXT_INT_3) { case 0: sb.append((char) ('0' + random.nextInt(NEXT_INT))); break; case 1: sb.append((char) ('a' + random.nextInt(NEXT_CHAR))); break; case 2: sb.append((char) ('A' + random.nextInt(NEXT_CHAR))); break; default: } } return sb.toString(); }  static String messageFormat(final String message, final Object... params); static String getTransactionID(); static String getRandomCode(); static String getRandomNumber(final int size); static String getRandomChar(final int size); static String getString(final Object obj); static String notNullStr(final String str); static Date getDate(final Long time); static Integer[] splitId(final String idStr, final String splitor); static Long[] splitIdsByLong(final String idStr, final String splitor); static Integer[] splitId(final String idStr); static boolean wildcardMatch(final Collection<String> rules, final String matchValue); static boolean wildcardMatch(final String rule, final String matchValue); static boolean match(final String rule, final String matchValue); static String removeAllSymbol(final String str); static String replaceAllBlank(final String str); static String replaceRedundantBlank(final String str); static boolean isNotEmpty(final T[] paramTypes); static boolean isEmpty(final T[] paramTypes);  }
@Test public void getRandomChar() { String str1 = CommonUtil.getRandomChar(NUM_100); String str2 = CommonUtil.getRandomChar(NUM_100); Assert.isTrue(str1.length() == NUM_100, ErrorCodeDef.SYSTEM_ERROR_10001); Assert.notEquals(str1, str2, ErrorCodeDef.SYSTEM_ERROR_10001); System.out.println("生成了两个不一样的随机字符串"); }