# Hackerrank CDF of Random Variates from Two Uniform Distributions

Trying to solve the math behind this hacker rank problem, but it's been a long time since grad school and I've forgotten a lot.

The question: There is an ideal random number generator, which given a positive integer M can generate any real number between 0 to M, and probability density function is uniform in [0, M].

Given two positive integers A and B and we generate x and y using a random number generator with uniform probability density function [0, A] and [0, B] respectively, what's the probability that x + y is less than C? where C is a positive integer. For simplicity sake, assume A <= B.

I ended with the following cases, but obviously my math is wrong.
Case 1: A == B == C
0.5
Case 2: C > A & C > B
1
Case 3: C > A & C <= B)
0.5*1+0.5*C/B
Case 4: C < A & C < B
0.5*C/A + 0.5*C/B

What am I missing here?

Solve it graphically: You pick a random point in an $A\times B$ rectangle and ask for the proportion of the area of it that is below the line given by $x+y=C$. Taking $A\le B$ for granted, we have to distinguish the cases
• $0<C\le A$ where the lower area is a triangle
• $A< C< B$ where the lower and upper area both are trapezoids
• $B\le C\le A+B$ where the upper area is a triangle
• $A+B\le C$ where the desired probability is $1$, obviously
Note that while you also have four cases, they are given by different conditions. In particular, $C>A\land C>B$ does not imply probability $1$