Generating a uniform distribution
Suppose we want N independent uniform points on an interval, sorted from left to right, but want to generate them one at a time in order. We can do this without generating all N points and sorting them.
The conditional distribution
Let be the order statistics of N independent draws. Conditional on , the k points below u are themselves uniform on . Their maximum is , so
Equivalently, because ,
Set the artificial upper boundary and apply this relation for . Each new point is sampled conditionally on the point immediately above it. This produces exactly the same joint distribution as sorting N independent uniform draws.
Code
import numpy as np
def uniform_ordinal(n, rng=np.random.default_rng()):
points = np.empty(n)
upper = 1.0
for k in range(n, 0, -1):
upper *= rng.beta(k, 1)
points[k - 1] = upper
return points
For an interval , transform the result with . The original code used the equivalent form.