/** * Generate random String with readable characters. This * method will use the {@link SecureRandom} * @param len the size of the string returned * @return the string generated */ public static String genRandomStr(int len) { E.illegalArgumentIf(len < 1); return genRandomX(len, symbols, SYMBOL_SIZE); }
/** * Generate random String with readable characters. This * method will use the {@link SecureRandom} * @param len the size of the string returned * @return the string generated */ public static String genRandomStr(int len) { E.illegalArgumentIf(len < 1); return genRandomX(len, symbols, SYMBOL_SIZE); }
/** * Generate random digital string with the size specified. The * method use the {@link SecureRandom} * @param len the number of digits in the string generated * @return a string contains random digits */ public static String genRandomDigits(int len) { E.illegalArgumentIf(len < 1); if (len < 10) { SecureRandom random = new SecureRandom(); int n = random.nextInt(POWER_OF_TEN[len]); int base = POWER_OF_TEN[len - 1]; if (n < base) { n += base; } return String.valueOf(n); } else { return genRandomX(len, digits, DIGITS_SIZE); } }
/** * Generate random digital string with the size specified. The * method use the {@link SecureRandom} * @param len the number of digits in the string generated * @return a string contains random digits */ public static String genRandomDigits(int len) { E.illegalArgumentIf(len < 1); if (len < 10) { SecureRandom random = new SecureRandom(); int n = random.nextInt(POWER_OF_TEN[len]); int base = POWER_OF_TEN[len - 1]; if (n < base) { n += base; } return String.valueOf(n); } else { return genRandomX(len, digits, DIGITS_SIZE); } }