SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BasicRandomStreamFactory.java
1/*
2 * Class: BasicRandomStreamFactory
3 * Description: basic random stream factory
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 umontreal.ssj.rng.RandomStream;
28import umontreal.ssj.rng.MRG32k3a;
29
41 private Class rsClass;
42
56 public BasicRandomStreamFactory(Class rsClass) {
57 checkRandomStreamClass(rsClass);
58 this.rsClass = rsClass;
59 }
60
66 public Class getRandomStreamClass() {
67 return rsClass;
68 }
69
81 public void setRandomStreamClass(Class rsClass) {
82 checkRandomStreamClass(rsClass);
83 this.rsClass = rsClass;
84 }
85
86 private void checkRandomStreamClass(final Class rsClass) {
87 if (!RandomStream.class.isAssignableFrom(rsClass))
88 throw new IllegalArgumentException("The random class must implement the RandomStream interface");
89 try {
90 rsClass.getConstructor(new Class[0]);
91 } catch (NoSuchMethodException nme) {
92 throw new IllegalArgumentException(
93 "The random stream class " + rsClass.getName() + " does not have a " + "nullary public constructor.");
94 }
95 }
96
98 try {
99 return (RandomStream) rsClass.newInstance();
100 } catch (IllegalAccessException iae) {
102 "Cannot access constructor for random stream class " + rsClass.getName(), iae);
103 } catch (InstantiationException ie) {
105 "Cannot instantiate random stream class " + rsClass.getName(), ie);
106 } catch (Exception e) {
108 "Exception while calling the nullary constructor for random stream class " + rsClass.getName(), e);
109 }
110 }
111
112 public String toString() {
113 return "Basic random stream factory constructing streams of class " + rsClass.getName();
114 }
115}
Class getRandomStreamClass()
Returns the random stream class associated with this object.
void setRandomStreamClass(Class rsClass)
Sets the associated random stream class to rsClass.
RandomStream newInstance()
Constructs and returns a new random stream.
BasicRandomStreamFactory(Class rsClass)
Constructs a new basic random stream factory with random stream class rsClass.
This exception is thrown when a random stream factory cannot instantiate a stream on a call to its um...
Represents a random stream factory capable of constructing instances of a given type of random stream...
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...