(String fname)
| 12 | List<String> words = new ArrayList<>(); |
| 13 | Random rand = new Random(47); |
| 14 | RandomWords(String fname) throws IOException { |
| 15 | List<String> lines = |
| 16 | Files.readAllLines(Paths.get(fname)); |
| 17 | // Skip the first line: |
| 18 | for(String line : lines.subList(1, lines.size())) { |
| 19 | for(String word : line.split("[ .?,]+")) |
| 20 | words.add(word.toLowerCase()); |
| 21 | } |
| 22 | } |
| 23 | @Override public String get() { |
| 24 | return words.get(rand.nextInt(words.size())); |
| 25 | } |