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 byConcurrentCachedGenerator
.
-
-
Constructor Summary
Constructors Constructor Description 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.ConcurrentCachedRNG(RandomNumberGenerator rng, int cacheSize)
Constructs a new instance which wraps the given random number generator and uses a cache of the specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
nextDouble()
Get the next randomdouble
.void
seed(long... seeds)
Delegate to the underlying random number generator.
-
-
-
Constructor Detail
-
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 generatorcacheSize
- the cache size- See Also:
ConcurrentCachedGenerator(dev.nm.stat.random.rng.concurrent.cache.ConcurrentCachedGenerator.Generator, int)
-
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 Detail
-
nextDouble
public double nextDouble()
Description copied from interface:RandomNumberGenerator
Get the next randomdouble
.- Specified by:
nextDouble
in interfaceRandomNumberGenerator
- Returns:
- the next random number
-
-