CommonsLang3RandomStringUtils { public static String randomAlphanumeric(final int count) { return random(count, true, true); } CommonsLang3RandomStringUtils(); static String random(final int count); static String randomAscii(final int count); static String randomAlphabetic(final int count); static String randomAlphanumeric(final int count); static String randomNumeric(final int count); static String random(final int count, final boolean letters, final boolean numbers); static String random(final int count, final int start, final int end, final boolean letters, final boolean numbers); static String random(final int count, final int start, final int end, final boolean letters, final boolean numbers, final char... chars); static String random(int count, int start, int end, final boolean letters, final boolean numbers,
                                final char[] chars, final Random random); static String random(final int count, final String chars); static String random(final int count, final char... chars);  }
@Test public void testRandomAlphaNumeric() { final char[] testChars = {'a', 'z', 'A', 'Z', '0', '9'}; final boolean[] found = {false, false, false, false, false, false}; for (int i = 0; i < 100; i++) { final String randString = CommonsLang3RandomStringUtils.randomAlphanumeric(10); for (int j = 0; j < testChars.length; j++) { if (randString.indexOf(testChars[j]) > 0) { found[j] = true; } } } for (int i = 0; i < testChars.length; i++) { if (!found[i]) { fail("alphanumeric character not generated in 1000 attempts: " + testChars[i] +" -- repeated failures indicate a problem "); } } }