UniformDistribution

class UniformDistribution(val min: Double = 0.0, val max: Double = 1.0) : ContinuousDistribution(source)

Represents the continuous uniform distribution, where all values in the interval [min, max] are equally likely.

The uniform distribution assigns constant probability density to every point within its support and zero density outside it. It is the simplest continuous distribution and is often used as a baseline or "uninformative" prior in Bayesian statistics, for random number generation, and in simulation when every outcome in a range should be equally probable.

The distribution is parameterized by min and max, which define the lower and upper bounds of the support. The probability density is constant and equal to 1 / (max - min) throughout the interval. The CDF increases linearly from 0 at min to 1 at max.

Example:

// Model a random arrival time uniformly distributed between 0 and 60 minutes
val dist = UniformDistribution(min = 0.0, max = 60.0)
dist.mean // 30.0
dist.variance // 300.0
dist.pdf(30.0) // 0.0167 (constant density across the interval)
dist.cdf(15.0) // 0.25 (25% chance of arriving in the first quarter)
dist.quantile(0.5) // 30.0 (the median equals the mean for a symmetric distribution)
dist.sample(Random(42)) // a single random arrival time in [0, 60]

// Standard uniform on [0, 1]
val standard = UniformDistribution.STANDARD
standard.cdf(0.5) // 0.5

Constructors

Link copied to clipboard
constructor(min: Double = 0.0, max: Double = 1.0)

Types

Link copied to clipboard
object Companion

Provides the pre-built standard uniform distribution constant.

Properties

Link copied to clipboard
open override val entropy: Double

The differential entropy of this distribution in nats, equal to the natural log of the range.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution, always -1.2 for any continuous uniform distribution.

Link copied to clipboard
val max: Double

the upper bound of the distribution's support. Must be strictly greater than min. Default is 1.0, which gives the standard uniform distribution on [0, 1].

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: Double

the lower bound of the distribution's support. Default is 0.0.

Link copied to clipboard
open override val skewness: Double

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

Link copied to clipboard
open override val variance: Double

The variance of this distribution, equal to the squared range divided by 12.

Functions

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

Computes the cumulative distribution function at x.

Link copied to clipboard
open override fun logPdf(x: Double): Double

Computes the natural logarithm of the probability density at x.

Link copied to clipboard
open override fun pdf(x: Double): Double

Computes the probability density at x.

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

Computes the quantile (inverse CDF) for the given probability p.

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

Draws a single random value uniformly from the interval [min, max].