SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BernoulliGen.java
1/*
2 * Class: BernoulliGen
3 * Description: random variate generators for the Bernoulli 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 Richard Simard
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.BernoulliDist;
28import umontreal.ssj.rng.RandomStream;
29
38public class BernoulliGen extends RandomVariateGenInt {
39 protected double p;
40
45 public BernoulliGen(RandomStream s, double p) {
46 super(s, new BernoulliDist(p));
47 setParams(p);
48 }
49
55 super(s, dist);
56 if (dist != null)
57 setParams(dist.getP());
58 }
59
64 public static int nextInt(RandomStream s, double p) {
65 return BernoulliDist.inverseF(p, s.nextDouble());
66 }
67
71 public double getP() {
72 return p;
73 }
74
78 protected void setParams(double p) {
79 if (p < 0.0 || p > 1.0)
80 throw new IllegalArgumentException("p not in range [0, 1]");
81 this.p = p;
82 }
83}
Extends the class DiscreteDistributionInt for the Bernoulli distribution slaw00a  with parameter ,...
static int inverseF(double p, double u)
Returns the inverse of the Bernoulli distribution function with parameter at .
BernoulliGen(RandomStream s, BernoulliDist dist)
Creates a random variate generator for the Bernoulli distribution dist and the random stream s.
void setParams(double p)
Sets the parameter of this object.
BernoulliGen(RandomStream s, double p)
Creates a Bernoulli random variate generator with parameter , using stream s.
double getP()
Returns the parameter of this object.
static int nextInt(RandomStream s, double p)
Generates a new integer from the Bernoulli distribution with parameter &#160;p, using the given 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,...