Class ConcurrentCachedRLG

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

public class ConcurrentCachedRLG extends Object implements RandomLongGenerator
This is a fast thread-safe wrapper for random long generators. This class is backed by ConcurrentCachedGenerator.
  • Constructor Details

    • ConcurrentCachedRLG

      public ConcurrentCachedRLG(RandomLongGenerator uniform, int cacheSize)
      Constructs a new instance which wraps the given random long 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 unnecessary computation of values at the tail.
      Parameters:
      uniform - the underlying generator
      cacheSize - the cache size
      See Also:
    • ConcurrentCachedRLG

      public ConcurrentCachedRLG(RandomLongGenerator uniform)
      Construct a new instance which wraps the given random long generator and uses a cache which has 1000 entries per available core.
      Parameters:
      uniform - the underlying generator
  • Method Details

    • nextLong

      public long nextLong()
      Description copied from interface: RandomLongGenerator
      Get the next random long.
      Specified by:
      nextLong in interface RandomLongGenerator
      Returns:
      the next random long
    • seed

      public void seed(long... seeds)
      Delegate to the underlying random long generator. Note: this method is NOT thread-safe.
      Specified by:
      seed in interface Seedable
      Parameters:
      seeds - the seeds
    • 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