P23 { public static <T> List<T> randomSelect(List<T> list, int n) { return new Random().ints(n, 0, list.size()).mapToObj(list::get).collect(Collectors.toList()); }  static List<T> randomSelect(List<T> list, int n); static List<T> randomSelectR(List<T> list, int n); static List<T> randomSelect_imperative(List<T> list, int n);  }
@Test public void shouldReturnAListOfThreeRandomSelectedElements() throws Exception { List<String> result = P23.randomSelect(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h"), 3); System.out.println(result); assertThat(result, hasSize(3)); }