fork(1) download
  1. //package warlords.backend.utilities;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.nio.charset.Charset;
  8. import java.nio.file.Files;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.Random;
  12.  
  13. /*public*/ class NameGenerator {
  14. private static HashMap<String, NameGenerator> cached;
  15.  
  16. private ArrayList<String> syllables = new ArrayList<String>();
  17. private int[] typicalLengths;
  18. private Random rng = new Random();
  19.  
  20. private NameGenerator() {}
  21.  
  22. private String newName() {
  23. int length = typicalLengths[rng.nextInt(typicalLengths.length)];
  24. StringBuilder rtn = new StringBuilder();
  25. for (int i = 0; i < length; i++) {
  26. rtn.append(syllables.get(rng.nextInt(syllables.size())));
  27. }
  28. return rtn.toString();
  29. }
  30.  
  31. public static void main(String[] args) throws NumberFormatException {
  32. java.util.Scanner in = new java.util.Scanner(System.in);
  33. String[] split_t = in.nextLine().split(", ?");
  34. NameGenerator gen = new NameGenerator();
  35. gen.typicalLengths = new int[split_t.length];
  36. for (int i = 0; i < gen.typicalLengths.length; i++) {
  37. gen.typicalLengths[i] = Integer.parseInt(split_t[i]);
  38. }
  39. while (in.hasNextLine()) {
  40. gen.syllables.add(in.nextLine());
  41. }
  42. for (int i = 0; i < 5; i++) {
  43. System.out.println(gen.newName());
  44. }
  45. }
  46. }
  47.  
Success #stdin #stdout 0.13s 321088KB
stdin
3,4,5
ab
ac
ad
af
ag
ah
aj
ak
al
am
an
ap
aq
ar
as
at
av
aw
ax
az
stdout
axalakas
agacak
avafalajaj
adakavarab
atalagagac