Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NameGenerator {
- private static final List<Alphabet> letters = Collections.unmodifiableList(Arrays.asList(Alphabet.values()));
- private static Random rand = new Random();
- public static String newName()
- {
- int size = 3 + rand.nextInt(4);
- StringBuilder stringBuilder = new StringBuilder();
- while (size > 0)
- {
- size--;
- stringBuilder.append(getRandomLetter());
- }
- stringBuilder.append(rand.nextInt(999999));
- return stringBuilder.toString();
- }
- private static String getRandomLetter()
- {
- return ((Alphabet)letters.get(rand.nextInt(letters.size()))).name();
- }
- private static enum Alphabet
- {
- 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;
- private Alphabet() {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement