Sample Uniform⚠ unverified
General Calculations / Monte Carlo · Draw a sample from a uniform distribution on the interval [a, b]
Parameters
| Input | Symbol | Unit | Default | Description |
|---|---|---|---|---|
| a | a | — | 1.0 | Lower bound of the interval |
| b | b | — | 1.0 | Upper bound of the interval |
| Output | Symbol | Unit | Description |
|---|---|---|---|
| result | x | — | A single random sample uniformly distributed on [a, b] |
The science & history
Understanding the Parameters
-
Bounds $a$ and $b$ — the interval limits. Every value between them is equally likely; nothing outside is possible. The width $b - a$ sets the spread (variance $(b-a)^2/12$) and $a$ locates the interval. For $a < b$ the draw lands somewhere in between with flat probability.
-
The standard uniform $U$ — the internally-drawn random number on $(0,1)$, the direct output of a pseudo-random generator. The transform $a + (b-a)U$ is just a linear rescaling of that unit interval onto $[a, b]$.
-
The output $x$ — a single realisation; over many calls the values fill $[a, b]$ evenly. In Monte Carlo work, uniform sampling models quantities known only to within bounds, and — via inverse-transform sampling — is the seed from which every other distribution is generated (Sample Weibull, and the $U_1, U_2$ inside Sample Normal).
-
Type B uncertainty connection. A rectangular (uniform) distribution of half-width $a$ has standard uncertainty $a/\sqrt3$ — the standard Type B assumption in metrology when only bounds are known (e.g. from a spec sheet). Uniform sampling is the Monte Carlo embodiment of that assumption.
Derivation (Approaching a Proof)
The transform is the simplest case of inverse-transform sampling. A standard uniform variable $U$ has cumulative distribution $F_U(u) = u$ on $[0,1]$. We want $X$ uniform on $[a,b]$, whose CDF is the linear ramp
$$F_X(x) = \frac{x - a}{b - a}, \qquad a \le x \le b.$$
Inverse-transform sampling sets $F_X(x) = U$ and solves for $x$:
$$\frac{x - a}{b - a} = U \quad\Longrightarrow\quad x = a + (b - a)\,U. \qquad\blacksquare$$
Because the target CDF is linear, the inverse is a simple affine map — no transcendental functions needed. This is why the uniform is the foundation: draw $U$, then apply the inverse CDF $F^{-1}$ of any target distribution to get a sample from it. The Weibull sampler (Sample Weibull) is exactly this with $F^{-1}(u) = \eta(-\ln(1-u))^{1/\beta}$; the normal needs the Box–Muller trick (Sample Normal) only because its inverse CDF has no closed form.
Dimensional check. $U$ is dimensionless; $a$ and $b$ share units, so $x = a + (b-a)U$ carries the units of $a$. $\checkmark$
History and Development
-
The root of random sampling. The uniform generator is the primitive from which all pseudo-random sampling is built. Decades of work went into good uniform generators — from linear congruential methods to the Mersenne Twister — because every downstream distribution inherits their quality (and their flaws).
-
Inverse-transform sampling. The principle that $F^{-1}(U)$ has distribution $F$ is the workhorse of variate generation, exact whenever the inverse CDF is available. The uniform is where it starts.
-
Metrology's rectangular distribution. In the GUM, a quantity known only to lie within $\pm a$ (a digital display's rounding, a manufacturer's "$\pm$" spec) is modelled as uniform, contributing a Type B standard uncertainty $a/\sqrt3$ — one of the most common uncertainty components in practice.
Related Concepts: Sample Normal, Sample Weibull, Normal Distribution PDF, Weibull Distribution PDF, Expanded Uncertainty
Notes: Registry calculator sample-uniform (unverified). Stochastic sampler — new random draw each call
(not reproducible); needs $a<b$ and many draws. $x = a + (b-a)U$ is inverse-transform sampling of the flat CDF —
the seed for all other distributions. Rectangular Type B uncertainty $= a/\sqrt3$. Defaults $a=b=1$ degenerate.