List of utility methods to do Random String
String | generateRandomString(int stringLength) generate Random String byte[] symbols = "abcdefghijklmnopqrstuvwxyz0123456789".getBytes(); Random random = new Random(); byte[] buffer = new byte[stringLength]; for (int i = 0; i < stringLength; i++) { buffer[i] = symbols[random.nextInt(symbols.length)]; return new String(buffer); |
String | generateRandomString(int wordsLength, String separator) Generates a string of random words with the supplied separator Random rand = new Random(); String sb = ""; for (int i = 0; i < wordsLength; i++) { int randomWord = rand.nextInt(words.length); if (i != 0) { sb += separator; sb += words[randomWord]; ... |
String | generateRandomString(Random random, int length) generate Random String return random.ints(48, 122).filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97)).mapToObj(i -> (char) i) .limit(length).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString(); |
String | generateRandomString(Random random, int size) generate Random String StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < size; i++) { char letter = (char) ((byte) 'A' + (byte) random.nextInt(26)); stringBuilder.append(letter); return stringBuilder.toString(); |
String | generateRandomString(Random rnd, char[] alphabet, int maxLength) generate Random String StringBuilder sb = new StringBuilder(); for (int i = 0; i < (rnd.nextInt(maxLength) + 1); i++) { sb.append(alphabet[rnd.nextInt(alphabet.length)]); return sb.toString(); |
String | generateRandomString(String str, int length) generate Random String String encoder = null; if (str == null || str.trim().length() == 0) { encoder = _CHARTECER; } else { encoder = str.trim(); StringBuilder randomString = new StringBuilder(); int limit = encoder.length(); ... |
String | genRandomString() Generates a random String of up to 10 characters
return genRandomString(rand.nextInt(10));
|
String | genRandomString(final int length) gen Random String byte[] data = new byte[length]; for (int i = 0; i < data.length; i++) { data[i] = pickupAlphabet(); return new String(data); |
String | genRandomString(int count) gen Random String return genRandomString(count, DEFAULT_CHARS);
|
String | getDefaultRandomName(String namePrefix) get Default Random Name if (namePrefix.length() > MAX_RESOURCE_LENGTH) { return String.format("%s%d", namePrefix.substring(0, MAX_RESOURCE_LENGTH).toLowerCase(), new Random().nextInt(1000000)); } else { return String.format("%s%d", namePrefix.toLowerCase(), new Random().nextInt(1000000)); |