P23 { public static <T> List<T> randomSelect_imperative(List<T> list, int n) { List<T> result = new ArrayList<>(); Random random = new Random(); List<T> remaining = list; while (result.size() < n) { Object[] objects = P20.removeAt0(remaining, random.nextInt(remaining.size())); remaining = (List<T>) objects[0]; T t = (T) objects[1]; result.add(t); } return result; }  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_imperative() throws Exception { List<String> result = P23.randomSelect_imperative(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h"), 3); System.out.println(result); assertThat(result, hasSize(3)); }