About this question
wrote a working random name generator in Java. Here's my code:
NameGenerator.java:
package pl.hubot.dev.name Generator;
import java.util.*;
import java.util.stream.Collectors;
public class NameGenerator {
private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
private static Random random = new Random();
void generate() {
WordChecker wordChecker = new WordChecker();
StringSimilarity stringSimilarity = new StringSimilarity();
Dictionary dictionary = new Dictionary();
final String filepath = "/usr/share/dict/american-english";
dictionary.build(filepath);
Listsyllabes = combination(CHARACTERS, 3).parallelStream() .filter((x) -> wordChecker.countSyllables(x) > 1).collect(Collectors.toList());
String word = "";
while (stringSimilarity.similarity(word, dictionary.getRandomEntries(1)[0]) < 0> word = syllables.get(random.nextInt(syllabes.size())) + syllabes.get(random.nextInt(syllabes.size()));
}
System.out.println(word);
}
private Setcombination(String input, int n) { Listletters = new ArrayList for (int i = 0; i < input.length(); ++i)();
letters.add(input.charAt(i));
Setresults = new HashSet combination("", letters, n, results);();
return results;
}
private void combination(String soFar, Listletters, int n, Setresults) { if (n == 0) {
results.add(soFar);
return;
}
int startIndex = soFar.length();
if (startIndex >= letters.size())
return;
for (int i = startIndex; i < letters> // ch is the next candidate to add to the result that we're
// building (soFar)
char ch = letters.get(i);
// Swap the characters at positions i and position startIndex.
char temp = letters.get(startIndex);
letters.set(i, temp);
letters.set(startIndex, ch);
// add ch to soFar, compute combinations of length n-1.
// as startIndex is essentially soFar.length() this means that
// the recursive call will only process the remainder of the list.
combination(soFar + ch, letters, n - 1, results);
// Swap the characters back - restore the original state.
letters.set(i, ch);
letters.set(startIndex, temp);
}
}
}
Could I ask about reviewing this code?