# Why is the distribution of rand()^2 different than of rand()*rand()?

In Libre Office Calc, the rand() function is available, which chooses a random value between 0 and 1 from a uniform distribution. I’m a bit rusty on my probability, so when I saw the following behaviour, I was puzzled:

A = 200×1 column of rand()^2

B = 200×1 column of rand()*rand()

mean(A) = 1/3

mean(B) = 1/4

Why is mean(A) != 1/4?

It may be helpful to think of rectangles. Imagine you have the chance to get land for free. The size of the land will be determined by (a) one realization of the random variable or (b) two realizations of the same random variable. In the first case (a), the area will be a square with the side length being equal to the sampled value. In the second case (b), the two sampled values will represent width and length of a rectangle. Which alternative do you choose?

Let $\mathbf{U}$ be a realization of a positive random variable.

a) The expected value of one realization $\mathbf{U}$ determines the area of the square which is equal to $\mathbf{U}^2$. On average, the size of the area will be

b) If there are two independent realizations $\mathbf{U}_1$ and $\mathbf{U}_2$, the area will be $\mathbf{U}_1 \cdot \mathbf{U}_2$. On average, the size equals

since both realizations are from the same distribution and independent.

When we calculate the difference between the size of the areas a) and b), we obtain

The above term is identical to $\mathop{\mathbb{Var}}[\mathbf{U}]$ which is inherently greater or equal to $0$.

This holds for the general case.

In your example, you sampled from the uniform distribution $\mathcal{U}(0,1)$. Hence,

With $\mathop{\mathbb{E}}[\mathbf{U}^2] = \mathop{\mathbb{Var}}[\mathbf{U}] + \mathop{\mathbb{E}^2}[\mathbf{U}]$ we obtain

These values were derived analytically but they match the ones you obtained with the random number generator.