@Test public void shouldPickRandomItemFromArray() { String[] countries = getISOCountries(); Set<String> countriesSet = newHashSet(getISOCountries()); Generator<String> countriesGenerator = new RandomFromCollectionGenerator<>(countries); for (int i = 0; i < 1000; i++) { countriesSet.remove(countriesGenerator.next()); } assertThat(countriesSet, hasSize(lessThan(30))); }
@Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next(); }
RandomFromCollectionGenerator implements Generator<T> { @Override public T next() { return exclusiveIndex > 0 ? items.get(random.nextInt(exclusiveIndex)) : null; } RandomFromCollectionGenerator(@Nonnull Collection<T> items); @SafeVarargs  RandomFromCollectionGenerator(T... items); @Override T next();  }