Class UniformInt
java.lang.Object
org.loudouncodes.randkit.discrete.UniformInt
- All Implemented Interfaces:
DiscreteDistribution
Discrete Uniform distribution on the closed integer interval
[a, b] with a ≤ b.
PMF: P(X = k) = 1 / (b - a + 1) for k ∈ [a, b], else 0.
CDF: F(k) = 0 for k < a; (k - a + 1)/(b - a + 1) for a ≤ k ≤ b;
and 1 for k > b.
Mean: (a + b) / 2. Variance: ((n^2 - 1) / 12), where n = b - a + 1.
-
Constructor Summary
ConstructorsConstructorDescriptionUniformInt(int a, int b) Constructs a UniformInt(a, b) using a platform-provided, high-quality default RNG.UniformInt(long seed, int a, int b) Constructs a UniformInt(a, b) with a deterministic seed.UniformInt(RandomGenerator rng, int a, int b) Constructs a UniformInt(a, b) using the provided generator. -
Method Summary
Modifier and TypeMethodDescriptiondoublecdf(int k) Cumulative distribution function (CDF).intThe inclusive lower bounda.doublemean()Theoretical mean of the distribution, when defined.doublepmf(int k) Probability mass function (PMF).intsample()Draw a single sample from the distribution.support()Returns the mathematical support of this distribution: the closed interval [a, b] (discrete).intThe inclusive upper boundb.doublevariance()Theoretical variance of the distribution, when defined.
-
Constructor Details
-
UniformInt
public UniformInt(int a, int b) Constructs a UniformInt(a, b) using a platform-provided, high-quality default RNG.- Parameters:
a- inclusive lower boundb- inclusive upper bound; must satisfya ≤ b- Throws:
IllegalArgumentException- ifa > b
-
UniformInt
public UniformInt(long seed, int a, int b) Constructs a UniformInt(a, b) with a deterministic seed.- Parameters:
seed- random seed for reproducibilitya- inclusive lower boundb- inclusive upper bound; must satisfya ≤ b- Throws:
IllegalArgumentException- ifa > b
-
UniformInt
Constructs a UniformInt(a, b) using the provided generator.- Parameters:
rng- non-null random generatora- inclusive lower boundb- inclusive upper bound; must satisfya ≤ b- Throws:
NullPointerException- ifrngis nullIllegalArgumentException- ifa > b
-
-
Method Details
-
sample
public int sample()Draw a single sample from the distribution.- Specified by:
samplein interfaceDiscreteDistribution- Returns:
- a random integer variate
-
pmf
public double pmf(int k) Probability mass function (PMF).- Specified by:
pmfin interfaceDiscreteDistribution- Parameters:
k- integer support value- Returns:
- P(X = k); 0.0 for values outside the support
-
cdf
public double cdf(int k) Cumulative distribution function (CDF).- Specified by:
cdfin interfaceDiscreteDistribution- Parameters:
k- integer cutoff- Returns:
- F(k) = P(X ≤ k), in the closed interval [0, 1]
-
mean
public double mean()Theoretical mean of the distribution, when defined.- Specified by:
meanin interfaceDiscreteDistribution- Returns:
- the mean; may be
Double.NaNif undefined
-
variance
public double variance()Theoretical variance of the distribution, when defined.- Specified by:
variancein interfaceDiscreteDistribution- Returns:
- the variance; may be
Double.NaNif undefined or infinite
-
support
Returns the mathematical support of this distribution: the closed interval [a, b] (discrete).- Returns:
- a
DistributionSupportdescribing[a, b]
-
lowerBound
public int lowerBound()The inclusive lower bounda.- Returns:
- the lower bound value
a
-
upperBound
public int upperBound()The inclusive upper boundb.- Returns:
- the upper bound value
b
-