### Question:
Do { public static <T> T sample(Collection source) { int size = source.size(); if (size <= 0) return null; int i = Do.randomInt(size); if (source instanceof List && source instanceof RandomAccess) return (T) ((List) source).get(i); else return (T) source.toArray()[i]; }  static byte[] read(String fileName); static byte[] read(InputStream inputStream); static String readToString(InputStream inputStream); static A checkSame(A oldValue, B newValue, Runnable onChanged); static T sample(Collection source); static SecureRandom getRng(); static int randomInt(int max); static byte[] randomBytes(int length); static byte[] randomNegativeBytes(int length); static int randomIntInRange(int inclusiveMinimum, int inclusiveMaximum); static byte[] read(File f); static void waitFor(Supplier<Boolean> function); static void delay(long millis, Action action); static void later(Action action); static HashMap<String, Object> map(Object... args); static Collection<T> collection(Object x); static ArrayList<T> list(U x); static ArrayList<T> listOf(U... objects); static boolean deepEqualityTest(Object a, Object b); static byte[] decodeBase64(String base64); static DeferredResult inParallel(final Task task); static DeferredResult inParallel(final TaskWithoutResult task); static String bytesToHex(byte[] bytes); static String snakeToCamelCase(String snakeString);  }### Answer:
@Test public void sample() throws Exception { HashSet<String> x = new HashSet<>(Do.listOf("aa", "bb", "cc", "cd")); HashSet<String> y = new HashSet<>(); ArrayList<String> z = new ArrayList<>(Do.listOf("aa", "bb", "cc", "cd")); HashSet<String> t = new HashSet<>(); int repetitions = 10000; for (int i = 0; i < repetitions; i++) { y.add(Do.sample(x)); t.add(Do.sample(z)); } assertEquals(y,x); }