Generate N samples from the uniform distribution: ri ~ U(0, 1), i = 1, ..., N
Python code
N = 40000# number of samplesr = np.random.rand(N)# Uniform random numbers in [0,1)
Each value ri is drawn independently from [0, 1)
The histogram below should look approximately flat (uniform)
Histogram of r
Mean of r
—
Std dev of r
—
Min
—
Max
—
Mathematical idea
Apply the inverse CDF of the Weibull distribution:
ti = τ · ( −ln(1 − ri) )1/β
with τ = 1.0, β = 1.5. This maps each uniform sample ri to a Weibull-distributed sample ti.
Why does this work?
The Weibull CDF is F(t) = 1 − exp(−(t/τ)β). Setting r = F(t) and solving for t gives: t = F−1(r) = τ·(−ln(1−r))1/β. Since r ~ U(0,1), then t = F−1(r) follows the Weibull distribution.
Python code
# Weibull parameters
tau = 1.0
beta = 1.5# Inverse transform samplingt = tau * (-np.log(1 - r))**(1 / beta)
Left: uniform input r → Right: transformed output t
Side-by-side: r (uniform) → t (Weibull)
Mean of t
—
Std dev of t
—
Max of t
—
Python code
delta_t = 0.1# Bin width
edges = np.arange(0, 5+delta_t, delta_t) # Bin edgescounts, _ = np.histogram(t, edges)# Count samples in each binpdf_est = counts / (N * delta_t)# Estimated PDF# Analytical PDF of the Weibull distribution
analytic = (beta/tau * (edges/tau)**(beta-1)) * np.exp(-(edges/tau)**beta)
How binning works — step by step
0.5080
Full comparison (all N samples, Δt = 0.1)
Red diamonds = estimated PDF; blue curve = analytical Weibull PDF
As N increases, the red diamonds converge to the blue curve