### Question:
IterableUtils { public static <T> T random(Iterable<T> iterable) { return random(iterable, 1).iterator().next(); } private  IterableUtils(); static long countNodes(GraphDatabaseService database); static long count(Iterable iterable); static boolean contains(Iterable<T> iterable, T object); static List<T> toList(Iterable<T> iterable); static T random(Iterable<T> iterable); static Iterable<T> random(Iterable<T> iterable, int numberOfSamples); static T getSingle(Iterator<T> iterator, String notFoundMessage); static T getSingle(Iterable<T> iterable, String notFoundMessage); static T getSingle(Iterator<T> iterator); static T getSingle(Iterable<T> iterable); static T getSingleOrNull(Iterator<T> iterator); static T getSingleOrNull(Iterable<T> iterable); static T getFirst(Iterator<T> iterator, String notFoundMessage); static T getFirst(Iterable<T> iterable, String notFoundMessage); static T getFirstOrNull(Iterator<T> iterator); static T getFirstOrNull(Iterable<T> iterable);  }### Answer:
@Test public void testRandom() { try (Transaction tx = database.beginTx()) { database.createNode(); tx.success(); } try (Transaction tx = database.beginTx()) { assertTrue(asList(0L, 1L).contains(random(database.getAllNodes()).getId())); assertTrue(asList(0L, 1L).contains(random(database.getAllNodes()).getId())); assertTrue(asList(0L, 1L).contains(random(database.getAllNodes()).getId())); assertTrue(asList(0L, 1L).contains(random(database.getAllNodes()).getId())); assertTrue(asList(0L, 1L).contains(random(database.getAllNodes()).getId())); } }
@Test public void randomSelectionShouldBeUniform() { int noSamples = 100; int noTrials = 1000000; double tolerance = 0.05; List<Integer> input = new LinkedList<>(); for (int i = 0; i < noSamples; i++) { input.add(i); } Counter<Integer> counter = new Counter<>(); for (int i = 0; i < noTrials; i++) { counter.increment(IterableUtils.random(input)); } for (int i = 0; i < noSamples; i++) { long count = counter.getCount(i); double lowerBound = (noTrials / noSamples) * (1 - tolerance); double upperBound = (noTrials / noSamples) * (1 + tolerance); assertTrue(count > lowerBound); assertTrue(count < upperBound); } }