### Question:
RandomSourceProvider { public static Seeder seed() { return seeder.get(); } private  RandomSourceProvider(); static RandomValues sourceOfRandomness(); static Seeder seed();  }### Answer:
@Test public void consistentSequenceOfBooleansShouldBeReturnedForKnownSeed() { final long seed = new Random().nextLong(); RandomSourceProvider.seed().next(seed); assertThat(from(randomValuesNextBoolean()).sample(100)) .containsExactlyElementsOf(expectedBooleansFor(seed)); }
@Test public void resettingTheSeedRevertsToTheInitialSeed() { final long initialSeed = RandomSourceProvider.seed().current(); final long nextSeed = new Random().nextLong(); RandomSourceProvider.seed().next(nextSeed); assertThat(RandomSourceProvider.seed().current()).isEqualTo(nextSeed); RandomSourceProvider.seed().previous(); assertThat(RandomSourceProvider.seed().current()).isEqualTo(initialSeed); }
@Test public void seedsCanBeSetAndRevertedInSequence() { final long initialSeed = RandomSourceProvider.seed().current(); RandomSourceProvider.seed().next(1); assertThat(RandomSourceProvider.seed().current()).isEqualTo(1); RandomSourceProvider.seed().next(2); assertThat(RandomSourceProvider.seed().current()).isEqualTo(2); RandomSourceProvider.seed().next(3); assertThat(RandomSourceProvider.seed().current()).isEqualTo(3); RandomSourceProvider.seed().previous(); assertThat(RandomSourceProvider.seed().current()).isEqualTo(2); RandomSourceProvider.seed().previous(); assertThat(RandomSourceProvider.seed().current()).isEqualTo(1); RandomSourceProvider.seed().previous(); assertThat(RandomSourceProvider.seed().current()).isEqualTo(initialSeed); }
@Test public void revertingSeedProvidesConsistentSequenceOfBooleans() { final long initialSeed = RandomSourceProvider.seed().current(); final List<Boolean> expectedBooleansForInitialSeed = expectedBooleansFor(initialSeed); final long nextRandomSeed = new Random().nextLong(); RandomSourceProvider.seed().next(nextRandomSeed); assertThat(from(randomValuesNextBoolean()).sample(100).asList()) .isNotEqualTo(expectedBooleansForInitialSeed); RandomSourceProvider.seed().previous(); assertThat(from(randomValuesNextBoolean()).sample(100).asList()) .isEqualTo(expectedBooleansForInitialSeed); }
@Test public void revertingToThePreviousSeedFromTheInitialSeedDoesNothing() throws ExecutionException, InterruptedException { final SeedHolder holder = new SeedHolder(); final ExecutorService executorService = Executors.newCachedThreadPool(); executorService.submit(() -> { holder.setSampleBefore(from(randomValuesNextBoolean()).sample(100)); holder.setStartingSeed(RandomSourceProvider.seed().current()); RandomSourceProvider.seed().previous(); holder.setSeed(RandomSourceProvider.seed().current()); holder.setSampleAfter(from(randomValuesNextBoolean()).sample(100)); }).get(); assertThat(holder.seed).isEqualTo(holder.startingSeed); assertThat(holder.sampleBefore.asList()).isNotEqualTo(holder.sampleAfter.asList()); }