@Test public void testRandomId() { String id1 = Identifiers.makeRandomId(4); Assert.assertEquals(id1.length(), 4); String id2 = Identifiers.makeRandomId(4); Assert.assertNotEquals(id1, id2); }
public static String makeRandomId(int l) { if (l<=0) return ""; char[] id = new char[l]; int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); int i = 0; id[i] = ID_VALID_START_CHARS.charAt(d % (26+26)); d /= (26+26); if (++i<l) do { id[i] = ID_VALID_NONSTART_CHARS.charAt(d%(26+26+10)); if (++i>=l) break; if (i%5==0) { d = random.nextInt( (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); } else { d /= (26+26+10); } } while (true); return new String(id); }
Identifiers { public static String makeRandomId(int l) { if (l<=0) return ""; char[] id = new char[l]; int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); int i = 0; id[i] = ID_VALID_START_CHARS.charAt(d % (26+26)); d /= (26+26); if (++i<l) do { id[i] = ID_VALID_NONSTART_CHARS.charAt(d%(26+26+10)); if (++i>=l) break; if (i%5==0) { d = random.nextInt( (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); } else { d /= (26+26+10); } } while (true); return new String(id); } }
Identifiers { public static String makeRandomId(int l) { if (l<=0) return ""; char[] id = new char[l]; int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); int i = 0; id[i] = ID_VALID_START_CHARS.charAt(d % (26+26)); d /= (26+26); if (++i<l) do { id[i] = ID_VALID_NONSTART_CHARS.charAt(d%(26+26+10)); if (++i>=l) break; if (i%5==0) { d = random.nextInt( (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); } else { d /= (26+26+10); } } while (true); return new String(id); }  }
Identifiers { public static String makeRandomId(int l) { if (l<=0) return ""; char[] id = new char[l]; int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); int i = 0; id[i] = ID_VALID_START_CHARS.charAt(d % (26+26)); d /= (26+26); if (++i<l) do { id[i] = ID_VALID_NONSTART_CHARS.charAt(d%(26+26+10)); if (++i>=l) break; if (i%5==0) { d = random.nextInt( (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); } else { d /= (26+26+10); } } while (true); return new String(id); }  static String makeRandomId(int l); static String makeRandomPassword(final int length); static String makeRandomPassword(final int length, String... passwordValidCharsPool); static String makeIdFromHash(long d); static String makeRandomJavaId(int l); static double randomDouble(); static long randomLong(); static boolean randomBoolean(); static int randomInt(); static int randomInt(int upbound); static byte[] randomBytes(byte[] buf); static byte[] randomBytes(int length); static String makeRandomBase64Id(int length); static String getBase64IdFromValue(long value); static String getBase64IdFromValue(long value, int length); static void appendBase64IdFromValueOfLength(long value, int length, StringBuffer sb); static void appendBase64IdFromValueOfLength(long value, int length, StringBuilder sb); static boolean isValidToken(String token, String validStartChars, String validSubsequentChars); }
Identifiers { public static String makeRandomId(int l) { if (l<=0) return ""; char[] id = new char[l]; int d = random.nextInt( (26+26) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); int i = 0; id[i] = ID_VALID_START_CHARS.charAt(d % (26+26)); d /= (26+26); if (++i<l) do { id[i] = ID_VALID_NONSTART_CHARS.charAt(d%(26+26+10)); if (++i>=l) break; if (i%5==0) { d = random.nextInt( (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10) * (26+26+10)); } else { d /= (26+26+10); } } while (true); return new String(id); }  static String makeRandomId(int l); static String makeRandomPassword(final int length); static String makeRandomPassword(final int length, String... passwordValidCharsPool); static String makeIdFromHash(long d); static String makeRandomJavaId(int l); static double randomDouble(); static long randomLong(); static boolean randomBoolean(); static int randomInt(); static int randomInt(int upbound); static byte[] randomBytes(byte[] buf); static byte[] randomBytes(int length); static String makeRandomBase64Id(int length); static String getBase64IdFromValue(long value); static String getBase64IdFromValue(long value, int length); static void appendBase64IdFromValueOfLength(long value, int length, StringBuffer sb); static void appendBase64IdFromValueOfLength(long value, int length, StringBuilder sb); static boolean isValidToken(String token, String validStartChars, String validSubsequentChars); static final String UPPER_CASE_ALPHA; static final String LOWER_CASE_ALPHA; static final String NUMERIC; static final String NON_ALPHA_NUMERIC; static final String JAVA_GOOD_START_CHARS; static final String JAVA_GOOD_NONSTART_CHARS; static final String JAVA_GOOD_SEGMENT_REGEX; static final String JAVA_GOOD_PACKAGE_OR_CLASS_REGEX; static final String JAVA_GOOD_BINARY_REGEX; static final String JAVA_GENERATED_IDENTIFIER_START_CHARS; static final String JAVA_GENERATED_IDENTIFIERNONSTART_CHARS; static final String BASE64_VALID_CHARS; static final String ID_VALID_START_CHARS; static final String ID_VALID_NONSTART_CHARS; static final String PASSWORD_VALID_CHARS; }