Class ConcurrentCachedRNG

java.lang.Object
dev.nm.stat.random.rng.concurrent.cache.ConcurrentCachedRNG
All Implemented Interfaces:
RandomNumberGenerator, Seedable

public class ConcurrentCachedRNG extends Object implements RandomNumberGenerator
This is a fast thread-safe wrapper for random number generators. This class is backed by ConcurrentCachedGenerator.
  • Constructor Details

    • ConcurrentCachedRNG

      public ConcurrentCachedRNG(RandomNumberGenerator rng, int cacheSize)
      Constructs a new instance which wraps the given random number generator and uses a cache of the specified size. A larger cache will make the simulation slightly faster at the expense of increased memory usage, but can lead to the computation of unnecessary values at the tail.
      Parameters:
      rng - the underlying generator
      cacheSize - the cache size
      See Also:
    • ConcurrentCachedRNG

      public ConcurrentCachedRNG(RandomNumberGenerator rng)
      Construct a new instance which wraps the given random number generator and uses a cache which has 8 entries per available core.
      Parameters:
      rng - the underlying generator
  • Method Details

    • nextDouble

      public double nextDouble()
      Description copied from interface: RandomNumberGenerator
      Get the next random double.
      Specified by:
      nextDouble in interface RandomNumberGenerator
      Returns:
      the next random number
    • seed

      public void seed(long... seeds)
      Delegate to the underlying random number generator. Note: this method is NOT thread-safe.
      Specified by:
      seed in interface Seedable
      Parameters:
      seeds - the seeds