Correlations  and Pearson Coefficient:

Here, our objective is to generate two sets of N numbers which have prescribed Mean and Standard Deviation and whose Pearson Correlation coefficient is also prescribed.

First we generate two collections of N numbers:
a1, a2, ... (that is, ak for k = 1, 2, ... N), with Mean = 0 and Standard Deviation = 1
and b1, b2, ... which (like the ak) has Mean = 0 and SD = 1.
(1)       (1/N)Σak = 0 and (1/N)Σak2 = 1
(2)       (1/N)Σbk = 0 and (1/N)Σbk2 = 1

If we're satisfied with normally distributed numbers, we can do this with Excel, using NORMINV(RAND(),0,1)
Further, we assume that these sets of numbers have Correlation = 0
... which would be the case if they were generated using NORMINV().
Then:
(3)       (1/N)Σak bk = 0.

From the above numbers we construct another collection, collection 1, namely
x1 = M1 + S1a1, x2 = M1 + S1a2, ... (which we represent by xk = M1 + S1ak   for k = 1, 2, ... N).

This collection will have mean = M1 and SD = S1, since
(1/N)Σxk = (1/N)Σ M1 + S1 (1/N)Σak = M1 + S1*0 = M1 and
(1/N)Σ(xk - M1)2 = S12 (1/N)Σak2 = S12*1 = S12

Similarly, we construct the collection 2, based upon the bk, namely
yk = M2 + S2b1   for k = 1, 2, ... N.
This collection will have mean = M2 and SD = S2,

So far we've been able to construct two sets of numbers (x and y) with prescribed Means and Standard Deviations, starting with two sets (a and b) with Mean = 0 and SD = 1. Now we work on the Pearson Correlation r:
r(x,y) = { (1/N)Σ (xk - M1) (yk - M2) } / { S1 S2 }     where the numerator is the Covariance between the x and y sets.

Hence:
r(x,y) = { (1/N)Σ S1 ak S2bk } / { S1 S2 } = (1/N)Σ ak bk = r(a,b)
so the correlation for the sets x and y is the same as for the sets a and b.
However, we're asuming that r(a,b) = 0, so r(x,y) = 0

Now we generate a u-set, like so:     uk = M1 + S1 (A ak + B bk)     where A and B are as-yet-unknown constants.
Note that the Mean of this u-set is:
    (1/N)Σuk = M1 + S1(A/N)Σak + S1(B/N)Σbk = M1 + 0 = M1     the same Mean as the x-set, namely M1.

Further, the Standard Deviation of this u-set is determined from:
    SD2 = (1/N)Σ(uk - M1)2 = S12(1/N)Σ (A ak + B bk)2 = S12(1/N) { A2 Σak2 + B2Σbk2 + 2ABΣakbk }

So, using (1), (2) and (3) we get:
(4)     SD2 = S12( A2 1 + B2 1 + 2AB 0 } = S12 (A2 + B2)
and, choosing A2 + B2 = 1, we get (finally):
    SD2 = S12     so the u-set has the same Standard Deviation the x-set, namely S1.

So far we've managed to modify the x-set, creating a u-set, yet maintaining the Mean and SD.

Now, we calculate the correlation:

r(u,y) = { (1/N)Σ (uk - M1) (yk - M2) } / { S1 S2 } = (1/N)Σ (A ak + B bk) bk = A 0 + B 1 = B     using (2) and (3).

Finally, then, we can start with uncorrelated sets x and y, specify a correlation B, and construct a u-set with the same Mean and SD as the x-set, namely M1 and S1 ... but with the specified correlation, via uk = M1 + S1 { SQRT(1-B2)ak + B bk }


Now we consider THREE sets: ak, bk and ck (with Mean = 0 and SD = 1) and three derived sets: xk, yk and zk ... all of which are uncorrelated.

We generate a u-set (as we did above) according to:
    uk = M1 + S1 { A ak + B bk + C ck }     with Mean M1 and Standard Deviation* S1     the same as the x-set

* Note:
For the u-set, SD2 = S1 2 (A2 + B2 + C2)     so SD = S1    provided A2 + B2 + C2 = 1

Now, for the correlations:

r(u,y) = { (1/N)Σ (uk - M1) (yk - M2) } / { S1 S2 } = (1/N)Σ (A ak + B bk + C ck) bk = A 0 + B 1 + C 0 = B

and
r(u,z) = { (1/N)Σ (uk - M1) (zk - M3) } / { S1 S3 } = (1/N)Σ (A ak + B bk + C ck) ck = A 0 + B 0 + C 1 = C

We now have sets u, v and y with prescribed Means and Standard Deviations, namely (M1,S1), (M2,S2) and (M3,S3), and correlations r(u,y) = B, r(u,z) = C.