String[] (String[] words, int wordsCount) { int len = words.length; int iterations = Math.min(len, wordsCount); Set<String> result = new TreeSet<>(); while (result.size() < iterations) { int i = rand(0, len - 1); result.add(words[i]); } return ArrayUtilRt.toStringArray(result); }