Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
You may find this post illuminating. – Sasha Mar 1 '12 at 22:24
Let $X=\sqrt{U}$. It is not hard to show that $X$ has density function $2x$ on $[0,1]$, $0$ elsewhere. So $X$ has part of the feature you want, its density function rises linearly. Scaling and relocating gets it to rise starting at $a$, at the right rate. Later you want a falling line, which will be taken care of by $-X$ suitably scaled and relocated. – André Nicolas Mar 1 '12 at 22:45
@marvinthemartian: By the way, the $\sqrt{U}$ was not arrived at by magic. One standard way to simulate a random variable $X$ is by using $F_X^{-1}(U)$, where $F_X^{-1}(x)$ is the inverse function of the cumulative distribution function of $X$. – André Nicolas Mar 1 '12 at 23:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.