SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RandomStreamManager.java
1/*
2 * Class: RandomStreamManager
3 * Description: Manages a list of random streams
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.rng;
26
27import java.util.List;
28import java.util.ArrayList;
29import java.util.Collections;
30import umontreal.ssj.rng.RandomStream;
31
45public class RandomStreamManager {
46 private List streams = new ArrayList();
47
57 public RandomStream add(RandomStream stream) {
58 if (stream == null)
59 throw new NullPointerException();
60 if (streams.contains(stream))
61 return stream;
62 streams.add(stream);
63 return stream;
64 }
65
74 public boolean remove(RandomStream stream) {
75 return streams.remove(stream);
76 }
77
81 public void clear() {
82 streams.clear();
83 }
84
93 public List getStreams() {
94 return Collections.unmodifiableList(streams);
95 }
96
101 public void resetStartStream() {
102 for (int s = 0; s < streams.size(); s++)
103 ((RandomStream) streams.get(s)).resetStartStream();
104 }
105
110 public void resetStartSubstream() {
111 for (int s = 0; s < streams.size(); s++)
112 ((RandomStream) streams.get(s)).resetStartSubstream();
113 }
114
119 public void resetNextSubstream() {
120 for (int s = 0; s < streams.size(); s++)
121 ((RandomStream) streams.get(s)).resetNextSubstream();
122 }
123
124 public String toString() {
125 StringBuffer sb = new StringBuffer(getClass().getName());
126 sb.append('[');
127 sb.append("number of stored streams: ").append(streams.size());
128 sb.append(']');
129 return sb.toString();
130 }
131}
Manages a list of random streams for more convenient synchronization.
List getStreams()
Returns an unmodifiable list containing all the random streams in this random stream manager.
void resetStartSubstream()
Forwards to the umontreal.ssj.rng.RandomStream.resetStartSubstream methods of all streams in the list...
void resetStartStream()
Forwards to the umontreal.ssj.rng.RandomStream.resetStartStream methods of all streams in the list.
RandomStream add(RandomStream stream)
Adds the given stream to the internal list of this random stream manager and returns the added stream...
void clear()
Removes all the streams from the internal list of this random stream manager.
void resetNextSubstream()
Forwards to the umontreal.ssj.rng.RandomStream.resetNextSubstream methods of all streams in the list.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...