public class BinomialVariate extends java.lang.Object implements DiscreteRandomVariate
n
= number of Bernoulli trialsprobability
= P{X=1} for Bernoulli trials.Note: This implementation uses the convolution method and has an execution time proportional to n.
Modifier and Type | Field and Description |
---|---|
private BernoulliVariate |
bernoulli
The BernoulliVariate that this BinomialVariate is based on.
|
protected int |
n
The parameter representing the number of Bernoulli trials.
|
Constructor and Description |
---|
BinomialVariate()
Creates new BinomialVariate with n and p set to zero.
|
Modifier and Type | Method and Description |
---|---|
double |
generate()
Generate a random variate having this class's distribution.
|
int |
generateInt()
Adds n Bernoulli variates together.
|
int |
getN()
Returns the number of Bernoulli trials.
|
java.lang.Object[] |
getParameters()
First element is n, wrapped in
Integer second is
probability, wrapped in Double |
double |
getProbability() |
RandomNumber |
getRandomNumber()
Gets the instance of RandomNumber that supports the underlying
BernoulliVariate.
|
void |
setN(int n)
Sets the number of Bernoulli trials.
|
void |
setParameters(java.lang.Object... params)
Sets parameters - first is n, the second is probability.
|
void |
setProbability(double p)
Sets the probability of success of one trial.
|
void |
setRandomNumber(RandomNumber rng)
Sets the instance of RandomNumber that supports the underlying
BernoulliVariate.
|
java.lang.String |
toString()
Returns a String containing the name of the distribution and the
parameters of this RandomVariate.
|
protected int n
private BernoulliVariate bernoulli
public BinomialVariate()
public RandomNumber getRandomNumber()
getRandomNumber
in interface RandomVariate
public void setRandomNumber(RandomNumber rng)
setRandomNumber
in interface RandomVariate
rng
- The RandomNumber instance supporting the generating algorithmpublic java.lang.Object[] getParameters()
Integer
second is
probability, wrapped in Double
getParameters
in interface RandomVariate
public void setParameters(java.lang.Object... params)
setParameters
in interface RandomVariate
params
- (n, probability)java.lang.IllegalArgumentException
- If the array does not contain exactly 2
elements, if the elements are not Numbers, if n is not positive, or if
the probability is not between 0 and 1.public int generateInt()
generateInt
in interface DiscreteRandomVariate
public double generate()
generate
in interface RandomVariate
public void setN(int n)
n
- # of Bernoulli trialsjava.lang.IllegalArgumentException
- If n is not positive.public int getN()
public void setProbability(double p)
p
- probability of successjava.lang.IllegalArgumentException
- If the argument is not between 0.0 and
1.0.public double getProbability()
public java.lang.String toString()
toString
in class java.lang.Object