List of utility methods to do Random String
String | getRandomString(int length) Generates a random string. String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Random rand = new Random(); StringBuilder value = new StringBuilder(); int charsLength = chars.length() - 1; for (int i = 0; i < length; i++) { value.append(chars.charAt(rand.nextInt(charsLength))); return value.toString(); ... |
String | getRandomString(int length) get Random String String base = "abcdefghijklmnopqrstuvwxyz0123456789"; return getRandomString(base, length); |
String | getRandomString(int length) get Random String Random r = new Random(); char min = 48; char max = 122; String ranStr = ""; for (int i = 0; i < length; i++) { char c = (char) (r.nextInt(max - min + 1) + min); ranStr += c; return ranStr; |
String | getRandomString(int length) get Random String StringBuffer bu = new StringBuffer(); String[] arr = { "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; Random random = new Random(); while (bu.length() < length) { String temp = arr[random.nextInt(57)]; if (bu.indexOf(temp) == -1) { ... |
String | getRandomString(int length) get Random String Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(3); long result = 0; switch (number) { case 0: result = Math.round(Math.random() * 25 + 65); ... |
String | getRandomString(int length) get Random String StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyz"); StringBuffer sb = new StringBuffer(); Random r = new Random(); int range = buffer.length(); for (int i = 0; i < length; i++) { sb.append(buffer.charAt(r.nextInt(range))); return sb.toString(); ... |
String | getRandomString(int length) get Random String char[] data = new char[length]; Random random = new Random(); for (int i = 0; i < length; i++) { data[i] = baseData[random.nextInt(baseDataLength)]; return new String(data); |
String | getRandomString(int length) get Random String StringBuffer r = new StringBuffer(length); String src = src_all; for (int i = 0; i < length; i++) { r.append(getRandomStr(src)); return r.toString(); |
String | getRandomString(int length) get Random String if (length <= 0) { length = 10; char[] pattern = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; StringBuilder result = new StringBuilder(); int n = pattern.length; ... |
String | getRandomString(int length) Generates a random string with the provided length. StringBuffer retObj = new StringBuffer(); String letters = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"; Random random = new Random(System.currentTimeMillis()); for (int i = 0; i < length; i++) { int pos = random.nextInt(letters.length()); retObj.append(letters.charAt(pos)); return retObj.toString(); ... |