### Question:
BiasedGenerator implements Generator<T> { @Override public T next() { return random.nextInt(100) + 1 > percentageBiasTowardsFirst ? secondGenerator.next() : firstGenerator.next(); } BiasedGenerator(int percentageBiasTowardsFirst, @Nonnull Generator<T> firstGenerator, @Nonnull Generator<T> secondGenerator); @Override T next();  }### Answer:
@Test public void shouldGenerateAbout20PercentOfFirstGenerator() { Generator<Boolean> firstGenerator = new GeneratorOfInstance<>(true); Generator<Boolean> secondGenerator = new GeneratorOfInstance<>(false); int biasTowardsFirst = 20; Generator<Boolean> biasedGenerator = new BiasedGenerator<>(biasTowardsFirst, firstGenerator, secondGenerator); int trueCount = 0; for (int i = 0; i < 10000; i++) { if (biasedGenerator.next()) { trueCount++; } } assertThat(trueCount, greaterThan(1500)); assertThat(trueCount, lessThan(2500)); }
@Test public void shouldGenerate100PercentOfFirstGenerator() { Generator<Boolean> firstGenerator = new GeneratorOfInstance<>(true); Generator<Boolean> secondGenerator = new GeneratorOfInstance<>(false); int biasTowardsFirst = 100; Generator<Boolean> biasedGenerator = new BiasedGenerator<>(biasTowardsFirst, firstGenerator, secondGenerator); int trueCount = 0; for (int i = 0; i < 10000; i++) { if (biasedGenerator.next()) { trueCount++; } } assertThat(trueCount, is(10000)); }
@Test public void shouldGenerate0PercentOfFirstGenerator() { Generator<Boolean> firstGenerator = new GeneratorOfInstance<>(true); Generator<Boolean> secondGenerator = new GeneratorOfInstance<>(false); int biasTowardsFirst = 0; Generator<Boolean> biasedGenerator = new BiasedGenerator<>(biasTowardsFirst, firstGenerator, secondGenerator); int trueCount = 0; for (int i = 0; i < 10000; i++) { if (biasedGenerator.next()) { trueCount++; } } assertThat(trueCount, is(0)); }