Class BernoulliTrial
- java.lang.Object
-
- dev.nm.stat.random.rng.univariate.BernoulliTrial
-
- All Implemented Interfaces:
RandomNumberGenerator,Seedable
public class BernoulliTrial extends Object implements RandomNumberGenerator
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:
- Wikipedia: Bernoulli trial
-
-
Constructor Summary
Constructors Constructor Description BernoulliTrial(RandomNumberGenerator rng, double p)Creates a new instance that uses the givenRandomNumberGeneratorto do the trial.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublenextDouble()Get the next randomdouble, which is either 1 (success) or 0 (failure).booleannextLogTrial()Performs a Bernoulli trial that succeeds with probability ep.static booleannextLogTrial(RandomNumberGenerator rng, double p)Performs a Bernoulli trial that succeeds with probability ep.booleannextTrial()Performs a Bernoulli trial that succeeds with probability p.static booleannextTrial(RandomNumberGenerator rng, double p)Performs a Bernoulli trial that succeeds with probability p.voidseed(long... seeds)Seed the random number/vector/scenario generator to produce repeatable experiments.
-
-
-
Constructor Detail
-
BernoulliTrial
public BernoulliTrial(RandomNumberGenerator rng, double p)
Creates a new instance that uses the givenRandomNumberGeneratorto do the trial.- Parameters:
rng- the random number generator that is to be usedp- the success probability
-
-
Method Detail
-
nextTrial
public static boolean nextTrial(RandomNumberGenerator rng, double p)
Performs a Bernoulli trial that succeeds with probability p.- Parameters:
rng- a random number generatorp- a success probability- Returns:
trueif the trial succeeded
-
nextTrial
public boolean nextTrial()
Performs a Bernoulli trial that succeeds with probability p.- Returns:
trueif the trial succeeded
-
nextLogTrial
public static boolean nextLogTrial(RandomNumberGenerator rng, double p)
Performs a Bernoulli trial that succeeds with probability ep.- Parameters:
rng- a random number generatorp- the log of a success probability- Returns:
trueif the trial succeeded
-
nextLogTrial
public boolean nextLogTrial()
Performs a Bernoulli trial that succeeds with probability ep.- Returns:
trueif the trial succeeded
-
nextDouble
public double nextDouble()
Get the next randomdouble, which is either 1 (success) or 0 (failure).- Specified by:
nextDoublein interfaceRandomNumberGenerator- Returns:
- the next random outcome (1 or 0)
-
-