SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
GeometricGen.java
1/*
2 * Class: GeometricGen
3 * Description: random variate generator for the geometric distribution
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.*;
28import umontreal.ssj.probdist.*;
29
42public class GeometricGen extends RandomVariateGenInt {
43 private double p;
44
49 public GeometricGen(RandomStream s, double p) {
50 super(s, new GeometricDist(p));
51 setParams(p);
52 }
53
58 super(s, dist);
59 if (dist != null)
60 setParams(dist.getP());
61 }
62
63 public int nextInt() {
64 return GeometricDist.inverseF(p, stream.nextDouble());
65 }
66
71 public static int nextInt(RandomStream s, double p) {
72 return GeometricDist.inverseF(p, s.nextDouble());
73 }
74
78 public double getP() {
79 return p;
80 }
81
85 protected void setParams(double p) {
86 if (p < 0.0 || p > 1.0)
87 throw new IllegalArgumentException("p not in range [0, 1]");
88 this.p = p;
89 }
90}
Extends the class DiscreteDistributionInt for the geometric distribution slaw00a  (page 322) with par...
static int inverseF(double p, double u)
Computes the inverse of the geometric distribution, given by ( FInvgeom ).
GeometricGen(RandomStream s, GeometricDist dist)
Creates a new generator for the distribution dist, using stream s.
GeometricGen(RandomStream s, double p)
Creates a geometric random variate generator with parameter , using stream s.
static int nextInt(RandomStream s, double p)
Generates a geometric random variate with parameter &#160;p, using stream s, by inversion.
double getP()
Returns the parameter of this object.
void setParams(double p)
Sets the parameter and of this object.
int nextInt()
Generates a random number (an integer) from the discrete distribution contained in this object.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...