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