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`

?

**Answer**

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 U be a realization of a positive random variable.

a) The expected value of one realization U determines the area of the square which is equal to U2. On average, the size of the area will be

E[U2]

b) If there are two independent realizations U1 and U2, the area will be U1⋅U2. On average, the size equals

E[U1⋅U2]=E2[U]

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

E[U2]−E2[U]

The above term is identical to Var[U] which is inherently greater or equal to 0.

This holds for the general case.

In your example, you sampled from the uniform distribution U(0,1). Hence,

E[U]=12

E2[U]=14

Var[U]=112

With E[U2]=Var[U]+E2[U] we obtain

E[U2]=112+14=13

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

**Attribution***Source : Link , Question Author : Jefftopia , Answer Author : cardinal*