List of utility methods to do Random String
String | getRandomString(int length) get Random String char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); return getRandomString(length, chars); |
String | getRandomString(int length) get Random String String RandomCode = ""; char[] codeSequence = { '3', '4', '5', '6', '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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; Random random = new Random(); StringBuffer randomCode = new StringBuffer(); for (int i = 0; i < length; i++) { String strRand = String.valueOf(codeSequence[random.nextInt(40)]); ... |
String | getRandomString(int length, Random rnd) get Random String String s = Long.toHexString(Double.doubleToLongBits(rnd.nextDouble())); StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < s.length() && i < length; i++) { strBuilder.append(s.charAt(Math.abs(rnd.nextInt()) % s.length())); return strBuilder.toString(); |
String | getRandomString(int length, String charset) Generate a random string using current time and charset Random rand = new Random(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); if (charset == null) { return sb.toString(); for (int i = 0; i < length; i++) { int pos = rand.nextInt(charset.length()); sb.append(charset.charAt(pos)); ... |
String | getRandomString(int min, int max) get Random String String newstring = new String(); Random rand = new Random(); int i; final char[] chars = { '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', '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', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '=', '+', '{', '}', '[', ']', '|', ':', ';', ',', '.', '?', '/', '~', ' ' }; ... |
String | getRandomString(int minLength, int maxLength) get Random String int length; if (minLength == maxLength) { length = minLength; } else { length = RANDOM.nextInt(maxLength - minLength) + minLength; char[] randomString = new char[length]; for (int x = 0; x < length; x++) { ... |
String | getRandomString(int randomPasswordLength) Generate random string for password return getRandomString(randomPasswordLength, RANDOM_PATTERN);
|
String | getRandomString(int size) get Random String Random random = new Random(); StringBuffer sb = new StringBuffer(size); for (int i = 0; i < size; i++) { sb.append(c[Math.abs(random.nextInt(CHART_LENGHT))]); return sb.toString(); |
String | getRandomString(int size) get Random String Random random = new Random(); StringBuffer sb = new StringBuffer(size); for (int i = 0; i < size; i++) { sb.append(c[Math.abs(random.nextInt()) % c.length]); return sb.toString(); |
String | getRandomString(int size) Generates a random String of length size using the default encoding scheme.
StringBuilder builder = new StringBuilder(size); for (int i = 0; i < size; i++) { char c = (char) (random.nextInt(126 - 33) + 33); builder.append(c); return builder.toString(); |