I am trying to generate an asymetric triangular distribution; a is lower limit, b is higher limit and c is mode.
I found this following way to generate a random variable $X$ with triangular distribution.
Let $β = (c-a)/(b-a)$
Let $U_1$ and $U_2$ be uniform on $[0,1]$
If $(U_1 ≤ β)$
$X = a + (c-a)\sqrt U_2$
$X = b - (b-c)\sqrt U_2$
As far as I understood:
Let $f(X)$ be pdf of triangular distribution. I think our $U_1$ determines whether our random variable X is smaller or greater than c. Since $β$ equals to the probability that a given number is smaller than c, this makes sense. After that, based on where $X$ value lies, we are generating a random variable with uniform distribution. If $X<$ c, X is uniformly distributed on [a,c], otherwise between [c,b] (but its cdf is decreasing).
However my beloved logic falls apart at one point. Why do we need to take square root of $U_1$? What am I missing?
Thanks in advance.