Class UniformInt

java.lang.Object
org.loudouncodes.randkit.discrete.UniformInt
All Implemented Interfaces:
DiscreteDistribution

public final class UniformInt extends Object implements 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

    Constructors
    Constructor
    Description
    UniformInt(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 Type
    Method
    Description
    double
    cdf(int k)
    Cumulative distribution function (CDF).
    int
    The inclusive lower bound a.
    double
    Theoretical mean of the distribution, when defined.
    double
    pmf(int k)
    Probability mass function (PMF).
    int
    Draw a single sample from the distribution.
    Returns the mathematical support of this distribution: the closed interval [a, b] (discrete).
    int
    The inclusive upper bound b.
    double
    Theoretical variance of the distribution, when defined.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 bound
      b - inclusive upper bound; must satisfy a ≤ b
      Throws:
      IllegalArgumentException - if a > b
    • UniformInt

      public UniformInt(long seed, int a, int b)
      Constructs a UniformInt(a, b) with a deterministic seed.
      Parameters:
      seed - random seed for reproducibility
      a - inclusive lower bound
      b - inclusive upper bound; must satisfy a ≤ b
      Throws:
      IllegalArgumentException - if a > b
    • UniformInt

      public UniformInt(RandomGenerator rng, int a, int b)
      Constructs a UniformInt(a, b) using the provided generator.
      Parameters:
      rng - non-null random generator
      a - inclusive lower bound
      b - inclusive upper bound; must satisfy a ≤ b
      Throws:
      NullPointerException - if rng is null
      IllegalArgumentException - if a > b
  • Method Details

    • sample

      public int sample()
      Draw a single sample from the distribution.
      Specified by:
      sample in interface DiscreteDistribution
      Returns:
      a random integer variate
    • pmf

      public double pmf(int k)
      Probability mass function (PMF).
      Specified by:
      pmf in interface DiscreteDistribution
      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:
      cdf in interface DiscreteDistribution
      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:
      mean in interface DiscreteDistribution
      Returns:
      the mean; may be Double.NaN if undefined
    • variance

      public double variance()
      Theoretical variance of the distribution, when defined.
      Specified by:
      variance in interface DiscreteDistribution
      Returns:
      the variance; may be Double.NaN if undefined or infinite
    • support

      public DistributionSupport support()
      Returns the mathematical support of this distribution: the closed interval [a, b] (discrete).
      Returns:
      a DistributionSupport describing [a, b]
    • lowerBound

      public int lowerBound()
      The inclusive lower bound a.
      Returns:
      the lower bound value a
    • upperBound

      public int upperBound()
      The inclusive upper bound b.
      Returns:
      the upper bound value b