SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RandomVariateGen.java
1/*
2 * Class: RandomVariateGen
3 * Description: base class for all random variate generators over the reals
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.randvar;
26
27import umontreal.ssj.rng.RandomStream;
28import umontreal.ssj.probdist.Distribution;
29
55public class RandomVariateGen {
56
57 protected RandomStream stream;
58 // the stream used for generating random variates
59
60 protected Distribution dist;
61 // the distribution used by this generator
62
63 // This constructor is needed for subclasses with no associated distribution.
64 protected RandomVariateGen() {
65 }
66
75 this.stream = s;
76 this.dist = dist;
77 }
78
88 public double nextDouble() {
89 return dist.inverseF(stream.nextDouble());
90 }
91
102 public void nextArrayOfDouble(double[] v, int start, int n) {
103 if (n <= 0)
104 throw new IllegalArgumentException("n must be positive.");
105 for (int i = 0; i < n; i++)
106 v[start + i] = nextDouble();
107 }
108
118 public double[] nextArrayOfDouble(int n) {
119 if (n <= 0)
120 throw new IllegalArgumentException("n must be positive.");
121 double[] v = new double[n];
122 for (int i = 0; i < n; i++)
123 v[i] = nextDouble();
124 return v;
125 }
126
133 return stream;
134 }
135
140 public void setStream(RandomStream stream) {
141 this.stream = stream;
142 }
143
150 return dist;
151 }
152
156 public String toString() {
157 if (dist != null)
158 return getClass().getSimpleName() + " with " + dist.toString();
159 else
160 return getClass().getSimpleName();
161 }
162
163}
void nextArrayOfDouble(double[] v, int start, int n)
Generates n random numbers from the continuous distribution contained in this object.
double[] nextArrayOfDouble(int n)
Generates n random numbers from the continuous distribution contained in this object,...
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
RandomVariateGen(RandomStream s, Distribution dist)
Creates a new random variate generator from the distribution dist, using stream s.
void setStream(RandomStream stream)
Sets the umontreal.ssj.rng.RandomStream used by this generator to stream.
RandomStream getStream()
Returns the umontreal.ssj.rng.RandomStream used by this generator.
Distribution getDistribution()
Returns the umontreal.ssj.probdist.Distribution used by this generator.
String toString()
Returns a String containing information about the current generator.
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...