SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
HypergeometricGen.java
1/*
2 * Class: HypergeometricGen
3 * Description: random variate generators for the hypergeometric 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
48public class HypergeometricGen extends RandomVariateGenInt {
49 private int m;
50 private int l;
51 private int k;
52
58 public HypergeometricGen(RandomStream s, int m, int l, int k) {
59 super(s, new HypergeometricDist(m, l, k));
60 setParams(m, l, k);
61 }
62
67 super(s, dist);
68 if (dist != null)
69 setParams(dist.getM(), dist.getL(), dist.getK());
70 }
71
78 public static int nextInt(RandomStream s, int m, int l, int k) {
79 return HypergeometricDist.inverseF(m, l, k, s.nextDouble());
80 }
81
85 public int getM() {
86 return m;
87 }
88
92 public int getL() {
93 return l;
94 }
95
99 public int getK() {
100 return k;
101 }
102
106 protected void setParams(int m, int l, int k) {
107 if (l <= 0)
108 throw new IllegalArgumentException("l must be greater than 0");
109 if (m <= 0 || m > l)
110 throw new IllegalArgumentException("m is invalid: 1<=m<l");
111 if (k <= 0 || k > l)
112 throw new IllegalArgumentException("k is invalid: 1<=k<l");
113 this.m = m;
114 this.l = l;
115 this.k = k;
116 }
117}
Extends the class DiscreteDistributionInt for the hypergeometric distribution rgen98a  (page 101) wit...
static int inverseF(int m, int l, int k, double u)
Computes for the hypergeometric distribution without using precomputed tables.
void setParams(int m, int l, int k)
Sets the parameter and of this object.
int getM()
Returns the associated with this object.
int getK()
Returns the associated with this object.
HypergeometricGen(RandomStream s, HypergeometricDist dist)
Creates a new generator for distribution dist, using stream s.
static int nextInt(RandomStream s, int m, int l, int k)
Generates a new variate from the hypergeometric distribution with parameters &#160;m, &#160;l and &#160;k,...
int getL()
Returns the associated with this object.
HypergeometricGen(RandomStream s, int m, int l, int k)
Creates a hypergeometric generator with parameters &#160;m, &#160;l and &#160;k, using stream s.
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,...