# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.random.rng.univariate

## Class BernoulliTrial

• java.lang.Object
• com.numericalmethod.suanshu.stats.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.
Wikipedia: Bernoulli trial
• ### Constructor Summary

Constructors
Constructor and Description
BernoulliTrial(RandomNumberGenerator rng, double p)
Creates a new instance that uses the given RandomNumberGenerator to do the trial.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double nextDouble()
Get the next random double, which is either 1 (success) or 0 (failure).
boolean nextLogTrial()
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 nextTrial()
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.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### BernoulliTrial

public BernoulliTrial(RandomNumberGenerator rng,
double p)
Creates a new instance that uses the given RandomNumberGenerator to do the trial.
Parameters:
rng - the random number generator that is to be used
p - 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 generator
p - 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

public static boolean nextLogTrial(RandomNumberGenerator rng,
double p)
Performs a Bernoulli trial that succeeds with probability ep.
Parameters:
rng - a random number generator
p - 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 random double, which is either 1 (success) or 0 (failure).
Specified by:
nextDouble in interface RandomNumberGenerator
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.
Specified by:
seed in interface Seedable
Parameters:
seeds - the seeds