Class BernoulliTrial
java.lang.Object
dev.nm.stat.random.rng.univariate.BernoulliTrial
- All Implemented Interfaces:
RandomNumberGenerator
,Seedable
A Bernoulli trial (or binomial trial) is a random experiment with exactly two possible outcomes,
"success" and "failure", in which the probability of success, p, is the same every time
the experiment is conducted.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBernoulliTrial
(RandomNumberGenerator rng, double p) Creates a new instance that uses the givenRandomNumberGenerator
to do the trial. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Get the next randomdouble
, which is either 1 (success) or 0 (failure).boolean
Performs a Bernoulli trial that succeeds with probability ep.static boolean
nextLogTrial
(RandomNumberGenerator rng, double p) Performs a Bernoulli trial that succeeds with probability ep.boolean
Performs a Bernoulli trial that succeeds with probability p.static boolean
nextTrial
(RandomNumberGenerator rng, double p) Performs a Bernoulli trial that succeeds with probability p.void
seed
(long... seeds) Seed the random number/vector/scenario generator to produce repeatable experiments.
-
Constructor Details
-
BernoulliTrial
Creates a new instance that uses the givenRandomNumberGenerator
to do the trial.- Parameters:
rng
- the random number generator that is to be usedp
- the success probability
-
-
Method Details
-
nextTrial
Performs a Bernoulli trial that succeeds with probability p.- Parameters:
rng
- a random number generatorp
- a success probability- Returns:
true
if the trial succeeded
-
nextTrial
public boolean nextTrial()Performs a Bernoulli trial that succeeds with probability p.- Returns:
true
if the trial succeeded
-
nextLogTrial
Performs a Bernoulli trial that succeeds with probability ep.- Parameters:
rng
- a random number generatorp
- the log of a success probability- Returns:
true
if the trial succeeded
-
nextLogTrial
public boolean nextLogTrial()Performs a Bernoulli trial that succeeds with probability ep.- Returns:
true
if the trial succeeded
-
nextDouble
public double nextDouble()Get the next randomdouble
, which is either 1 (success) or 0 (failure).- Specified by:
nextDouble
in interfaceRandomNumberGenerator
- Returns:
- the next random outcome (1 or 0)
-
seed
public void seed(long... seeds) Description copied from interface:Seedable
Seed the random number/vector/scenario generator to produce repeatable experiments.
-