- All Implemented Interfaces:
public class RandomStreamWithCacheextends Objectimplements RandomStreamThis class represents a random stream whose uniforms are cached for more efficiency when using common random numbers. An object from this class is constructed with a reference to a
RandomStreaminstance used to get the random numbers. These numbers are stored in an internal array to be retrieved later. The dimension of the array increases as the values are generated. If the
nextDoublemethod is called after the object is reset, it gives back the cached values instead of computing new ones. If the cache is exhausted before the stream is reset, new values are computed, and added to the cache.
Such caching allows for a better performance with common random numbers, when generating uniforms is time-consuming. It can also help with restoring the simulation to a certain state without setting stream-specific seeds. However, using such caching may lead to memory problems if a large quantity of random numbers are needed.