我找到了适当的解决方案。Random提供了一些返回流的方法。例如ints(size)会创建一个随机整数流。
public List<String> createList(int listSize){ Random rand = new Random(); List<String> wordList = rand. ints(listSize, 0, sourceWords.size()). mapToObj(i -> sourceWords.get(i)). collect(Collectors.toList()); return wordList;}


