Class ReseedingThreadLocalRandomWrapper

    • Constructor Detail

      • ReseedingThreadLocalRandomWrapper

        public ReseedingThreadLocalRandomWrapper​(SeedGenerator seedGenerator,
                                                 java8.util.function.Supplier<? extends BaseRandom> initializer)
        Wraps the given Supplier. Uses the given SimpleRandomSeeder to reseed PRNGs, but not to initialize them unless the Supplier does so. This ThreadLocalRandomWrapper will be serializable if the Supplier is serializable.
        Parameters:
        initializer - a supplier that will be called to provide the initial BaseRandom for each thread.
        seedGenerator - The seed generation strategy whose SimpleRandomSeeder will be used to reseed each thread's PRNG.
      • ReseedingThreadLocalRandomWrapper

        public ReseedingThreadLocalRandomWrapper​(java8.util.function.Supplier<? extends BaseRandom> initializer,
                                                 SimpleRandomSeeder randomSeederThread)
        Wraps the given Supplier. Uses the given SimpleRandomSeeder to reseed PRNGs, but not to initialize them unless the Supplier does so. This ThreadLocalRandomWrapper will be serializable if the Supplier is serializable.
        Parameters:
        initializer - a supplier that will be called to provide the initial BaseRandom for each thread
        randomSeederThread - a random seeder that will reseed the PRNG for each thread when necessary
      • ReseedingThreadLocalRandomWrapper

        public ReseedingThreadLocalRandomWrapper​(int seedSize,
                                                 SeedGenerator seedGenerator,
                                                 java8.util.function.Function<byte[],​? extends BaseRandom> creator)
                                          throws SeedException
        Wraps a seed generator and a function that takes a seed byte array as input. This ReseedingThreadLocalRandomWrapper will be serializable if the Function is serializable.
        Parameters:
        seedSize - the size of seed arrays to generate.
        seedGenerator - The seed generation strategy that will provide the seed value for each thread's BaseRandom, both at initialization and through the corresponding SimpleRandomSeeder.
        creator - a Function that creates a BaseRandom from each seed. Probably a constructor reference.
        Throws:
        SeedException - if seedGenerator fails to generate an initial seed
      • ReseedingThreadLocalRandomWrapper

        public ReseedingThreadLocalRandomWrapper​(int seedSize,
                                                 SimpleRandomSeeder randomSeederThread,
                                                 java8.util.function.Function<byte[],​? extends BaseRandom> creator,
                                                 SeedGenerator seedGenerator)
                                          throws SeedException
        Wraps a seed generator and a function that takes a seed byte array as input. This ReseedingThreadLocalRandomWrapper will be serializable if the Function is serializable.
        Parameters:
        seedSize - the size of seed arrays to generate.
        randomSeederThread - The random seeder to use for reseeding.
        creator - a Function that creates a BaseRandom from each seed.
        seedGenerator - the seed generator for initialization.
        Throws:
        SeedException - if seedGenerator fails to generate an initial seed
    • Method Detail

      • wrapLegacy

        public static ReseedingThreadLocalRandomWrapper wrapLegacy​(java8.util.function.LongFunction<Random> legacyCreator,
                                                                   SeedGenerator seedGenerator)
        Uses this class and RandomWrapper to decorate any implementation of Random that can be constructed from a long seed into a fully-concurrent one.
        Parameters:
        legacyCreator - a function that provides the Random that underlies the returned wrapper on each thread, taking a seed as input.
        seedGenerator - the seed generator whose output will be fed to legacyCreator.
        Returns:
        a ThreadLocalRandomWrapper decorating instances created by legacyCreator.