UniformDiscreteDistribution

Represents the discrete uniform distribution, where all integer outcomes in a finite range are equally likely.

Every integer from min to max (inclusive) has the same probability of being observed. This is the discrete analogue of the continuous uniform distribution and models situations where each outcome is equally probable, such as rolling a fair die (min = 1, max = 6), selecting a random integer from a range, or choosing a random index in an array.

The support is {min, min + 1, ..., max}, giving max - min + 1 equally likely outcomes. The distribution is always symmetric, so the skewness is zero.

Example:

// Fair six-sided die
val die = UniformDiscreteDistribution(min = 1, max = 6)
die.pmf(3) // 0.1667 (each face has probability 1/6)
die.cdf(3) // 0.5 (probability of rolling 3 or less)
die.mean // 3.5
die.variance // 2.9167
die.quantileInt(0.5) // 3 (median)
die.sample(Random(42)) // a single random roll

// Random array index
val idx = UniformDiscreteDistribution(min = 0, max = 99)
idx.pmf(50) // 0.01 (each index equally likely)

Constructors

Link copied to clipboard
constructor(min: Int, max: Int)

Properties

Link copied to clipboard
open override val entropy: Double

The Shannon entropy of this distribution in nats, equal to the natural log of the number of outcomes.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution. Returns Double.NaN when there is only one outcome.

Link copied to clipboard
val max: Int

the largest value in the support (inclusive). Must be greater than or equal to min.

Link copied to clipboard
open override val mean: Double

The mean of this distribution, equal to the midpoint of min and max.

Link copied to clipboard
val min: Int

the smallest value in the support (inclusive).

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution, always zero because the discrete uniform distribution is symmetric.

Link copied to clipboard
open override val variance: Double

The variance of this distribution.

Functions

Link copied to clipboard
open override fun cdf(k: Int): Double

Returns the cumulative distribution function value at k.

Link copied to clipboard
open override fun logPmf(k: Int): Double

Returns the natural logarithm of the probability mass at k.

Link copied to clipboard
open override fun pmf(k: Int): Double

Returns the probability mass at k.

Link copied to clipboard
open override fun quantileInt(p: Double): Int

Returns the quantile (inverse CDF) for the given probability p as an Int.

Link copied to clipboard
open override fun sample(random: Random): Int

Draws a single random value from this uniform discrete distribution.