25package umontreal.ssj.rng;
27import cern.colt.list.DoubleArrayList;
49 private DoubleArrayList values;
50 private int index = 0;
51 private boolean caching =
true;
61 throw new NullPointerException(
"The given random stream cannot be null");
63 values =
new DoubleArrayList();
78 throw new NullPointerException(
"The given random stream cannot be null");
80 values =
new DoubleArrayList(initialCapacity);
101 if (this.caching && !caching)
103 this.caching = caching;
124 throw new NullPointerException(
"The given random stream cannot be null");
125 if (stream == this.stream)
127 this.stream = stream;
140 values =
new DoubleArrayList();
161 return values.size();
188 if (newIndex < 0 || newIndex > values.size())
189 throw new IllegalArgumentException(
"newIndex must not be negative or greater than the cache size");
211 throw new NullPointerException();
212 this.values = values;
213 index = values.size();
217 stream.resetStartStream();
221 stream.resetStartSubstream();
225 stream.resetNextSubstream();
230 return stream.nextDouble();
231 else if (index >= values.size()) {
232 double v = stream.nextDouble();
237 return values.getQuick(index++);
242 stream.nextArrayOfDouble(u, start, n);
245 int remainingValues = values.size() - index;
246 if (remainingValues < 0)
248 int ncpy = Math.min(n, remainingValues);
250 System.arraycopy(values.elements(), index, u, start, ncpy);
255 stream.nextArrayOfDouble(u, start + ncpy, ngen);
256 for (
int i = ncpy; i < n; i++) {
257 values.add(u[start + i]);
264 return i + (int) (
nextDouble() * (j - i + 1));
268 for (
int x = start; x < start + n; x++)
int nextInt(int i, int j)
Returns a (pseudo)random number from the discrete uniform distribution over the integers ,...
void nextArrayOfDouble(double[] u, int start, int n)
Generates n (pseudo)random numbers from the uniform distribution and stores them into the array u sta...
boolean isCaching()
Determines if the random stream is caching values, default being true.
RandomStreamWithCache(RandomStream stream)
Constructs a new cached random stream with internal stream stream.
void setCachedValues(DoubleArrayList values)
Sets the array list containing the cached values to values.
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream:
int getNumCachedValues()
Returns the total number of values cached by this random stream.
void nextArrayOfInt(int i, int j, int[] u, int start, int n)
Generates n (pseudo)random numbers from the discrete uniform distribution over the integers ,...
void resetStartSubstream()
Reinitializes the stream to the beginning of its current substream:
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...
void setCachedStream(RandomStream stream)
Sets the random stream whose values are cached to stream.
void initCache()
Resets this random stream to recover values from the cache.
void setCaching(boolean caching)
Sets the caching indicator to caching.
void setCacheIndex(int newIndex)
Sets the index, in the cache, of the next value returned by nextDouble.
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .
RandomStreamWithCache(RandomStream stream, int initialCapacity)
Constructs a new cached random stream with internal stream stream.
int getCacheIndex()
Return the index of the next cached value that will be returned by the stream.
RandomStream getCachedStream()
Returns a reference to the random stream whose values are cached.
void clearCache()
Clears the cached values for this random stream.
DoubleArrayList getCachedValues()
Returns an array list containing the values cached by this random stream.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...