Class ConcurrentCachedRNG
java.lang.Object
dev.nm.stat.random.rng.concurrent.cache.ConcurrentCachedRNG
- All Implemented Interfaces:
RandomNumberGenerator
,Seedable
This is a fast thread-safe wrapper for random number generators. This class
is backed by
ConcurrentCachedGenerator
.-
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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
Modifier and TypeMethodDescriptiondouble
Get the next randomdouble
.void
seed
(long... seeds) Delegate to the underlying random number generator.
-
Constructor Details
-
ConcurrentCachedRNG
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:
-
ConcurrentCachedRNG
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 randomdouble
.- Specified by:
nextDouble
in interfaceRandomNumberGenerator
- 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.
-