SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BinomialGen.java
1/*
2 * Class: BinomialGen
3 * Description: random variate generators for the binomial 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.probdist.*;
28import umontreal.ssj.rng.*;
29
46public class BinomialGen extends RandomVariateGenInt {
47 protected int n = -1;
48 protected double p = -1.0;
49
54 public BinomialGen(RandomStream s, int n, double p) {
55 super(s, new BinomialDist(n, p));
56 setParams(n, p);
57 }
58
64 super(s, dist);
65 if (dist != null)
66 setParams(dist.getN(), dist.getP());
67 }
68
73 public static int nextInt(RandomStream s, int n, double p) {
74 return BinomialDist.inverseF(n, p, s.nextDouble());
75 }
76
80 public int getN() {
81 return n;
82 }
83
87 public double getP() {
88 return p;
89 }
90
94 protected void setParams(int n, double p) {
95 if (p < 0.0 || p > 1.0)
96 throw new IllegalArgumentException("p not in range [0, 1]");
97 if (n <= 0)
98 throw new IllegalArgumentException("n <= 0");
99 this.p = p;
100 this.n = n;
101 }
102}
Extends the class DiscreteDistributionInt for the binomial distribution slaw00a  (page 321) with para...
static int inverseF(int n, double p, double u)
Computes , the inverse of the binomial distribution.
BinomialGen(RandomStream s, BinomialDist dist)
Creates a random variate generator for the binomial distribution dist and the random stream s.
double getP()
Returns the parameter of this object.
BinomialGen(RandomStream s, int n, double p)
Creates a binomial random variate generator with parameters and , using stream s.
static int nextInt(RandomStream s, int n, double p)
Generates a new integer from the binomial distribution with parameters &#160;n and &#160;p,...
int getN()
Returns the parameter of this object.
void setParams(int n, double p)
Sets the parameter and of 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,...