List of utility methods to do Random String
TreeMap | randomizeMap(Map randomize Map Random r = new Random(); TreeMap<String, Integer> new_map = new TreeMap<String, Integer>(); for (String m : map.keySet()) { new_map.put(r.nextInt(10) + ":" + m, map.get(m)); return new_map; |
String | randomlyRecaseCodePoints(Random random, String str) Randomly upcases, downcases, or leaves intact each code point in the given string StringBuilder builder = new StringBuilder(); int pos = 0; while (pos < str.length()) { int codePoint = str.codePointAt(pos); pos += Character.charCount(codePoint); switch (nextInt(random, 0, 2)) { case 0: builder.appendCodePoint(Character.toUpperCase(codePoint)); ... |
String | randomNumberString(int in) { method in = Math.max(1, Math.min(in, 256)); StringBuffer sb = new StringBuffer(); for (int i = 0; i < in; i++) { char c = (char) Math.min('9', ('0' + randomInt(10))); sb.append(c); return (sb.toString()); |
String | randomRealisticUnicodeString(Random r) Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block. return randomRealisticUnicodeString(r, 20);
|
String | randomString() random String return "test_" + Long.toHexString(Double.doubleToLongBits(Math.random())); |
String | randomString() Generate a random string, of a specified length. return Long.toString(random.nextLong(), 36);
|
String | randomString(final int length) random String Random random = new Random(); final char[] chars = new char[length]; for (int i = 0, x = chars.length; i < x;) { do { final int cp = random.nextInt(0x10FFFF + 1); if (!Character.isDefined(cp)) { continue; final char[] chs = Character.toChars(cp); if (chs.length > x - i) { continue; for (final char ch : chs) { chars[i++] = ch; break; } while (true); return new String(chars); |
String | randomString(int len) random String StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { sb.append(randomLetter()); return sb.toString(); |
String | randomString(int length) random String if (length < 1) { return null; if (randGen == null) { synchronized (initLock) { if (randGen == null) { randGen = new Random(); numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" ... |
String | randomString(int length) randomString(...) method returns a string of specific length based on random characters. char[] chars = "ab1@cd2#ef3$gh4%ij5^kl6&mn7_op8-qr9?st0~uv3~wx7!yz".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c); return sb.toString(); ... |