25package umontreal.ssj.randvar;
27import umontreal.ssj.randvar.RandomVariateGen;
28import cern.colt.list.DoubleArrayList;
29import umontreal.ssj.rng.RandomStream;
30import umontreal.ssj.probdist.Distribution;
52 private RandomVariateGen rvg;
53 private DoubleArrayList values;
54 private int index = 0;
55 private boolean caching =
true;
66 throw new NullPointerException(
"The given random variate generator cannot be null");
68 values =
new DoubleArrayList();
83 throw new NullPointerException(
"The given random variate generator cannot be null");
85 values =
new DoubleArrayList(initialCapacity);
107 if (this.caching && !caching)
109 this.caching = caching;
130 throw new NullPointerException(
"The given random variate generator cannot be null");
146 values =
new DoubleArrayList();
168 return values.size();
195 if (newIndex < 0 || newIndex > values.size())
196 throw new IllegalArgumentException(
"newIndex must not be negative or greater than the cache size");
219 throw new NullPointerException();
220 this.values = values;
221 index = values.size();
226 return rvg.nextDouble();
227 else if (index >= values.size()) {
228 double v = rvg.nextDouble();
233 return values.getQuick(index++);
238 rvg.nextArrayOfDouble(v, start, n);
241 int remainingValues = values.size() - index;
242 if (remainingValues < 0)
244 int ncpy = Math.min(n, remainingValues);
246 System.arraycopy(values.elements(), index, v, start, ncpy);
251 rvg.nextArrayOfDouble(v, start + ncpy, ngen);
252 for (
int i = ncpy; i < n; i++) {
253 values.add(v[start + i]);
260 return rvg.getStream();
264 return rvg.getDistribution();
void setCachedGen(RandomVariateGen rvg)
Sets the random variate generator whose values are cached to rvg.
int getCacheIndex()
Return the index of the next cached value that will be returned by the generator.
int getNumCachedValues()
Returns the total number of values cached by this generator.
void setCachedValues(DoubleArrayList values)
Sets the array list containing the cached values to values.
RandomStream getStream()
Returns the umontreal.ssj.rng.RandomStream used by this generator.
RandomVariateGenWithCache(RandomVariateGen rvg, int initialCapacity)
Constructs a new cached random variate generator with internal generator rvg.
void nextArrayOfDouble(double[] v, int start, int n)
Generates n random numbers from the continuous distribution contained in this object.
Distribution getDistribution()
Returns the umontreal.ssj.probdist.Distribution used by this generator.
void initCache()
Resets this generator to recover values from the cache.
RandomVariateGenWithCache(RandomVariateGen rvg)
Constructs a new cached random variate generator with internal generator rvg.
void clearCache()
Clears the cached values for this cached generator.
void setCacheIndex(int newIndex)
Sets the index, in the cache, of the next value returned by nextDouble.
DoubleArrayList getCachedValues()
Returns an array list containing the values cached by this random variate generator.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
boolean isCaching()
Determines if the random variate generator is caching values, default being true.
void setCaching(boolean caching)
Sets the caching indicator to caching.
RandomVariateGen getCachedGen()
Returns a reference to the random variate generator whose values are cached.
This interface should be implemented by all classes supporting discrete and continuous distributions.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...