Advertisement
Guest User

Untitled

a guest
Sep 19th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. public class NameGenerator {
  2.   private static final List<Alphabet> letters = Collections.unmodifiableList(Arrays.asList(Alphabet.values()));
  3.   private static Random rand = new Random();
  4.  
  5.   public static String newName()
  6.   {
  7.     int size = 3 + rand.nextInt(4);
  8.    
  9.     StringBuilder stringBuilder = new StringBuilder();
  10.     while (size > 0)
  11.     {
  12.       size--;
  13.       stringBuilder.append(getRandomLetter());
  14.     }
  15.     stringBuilder.append(rand.nextInt(999999));
  16.    
  17.     return stringBuilder.toString();
  18.   }
  19.  
  20.   private static String getRandomLetter()
  21.   {
  22.     return ((Alphabet)letters.get(rand.nextInt(letters.size()))).name();
  23.   }
  24.  
  25.   private static enum Alphabet
  26.   {
  27.     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;
  28.    
  29.     private Alphabet() {}
  30.   }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement