# How to (efficiently) generate and catch some data-set that has similar correlation?

run:=Module[
{cor1,cor2,x1,x2,y1,y2},
cor1=0.5;cor2=0.4;

While[
cor1!=cor2,
cor1 =Round[Correlation[x1 = RandomReal[10, 10], y1 = RandomReal[10, 10]],0.001];
cor2 =Round[Correlation[x2 = RandomReal[10, 20], y2 = RandomReal[10, 20]],0.001];
];

(*Print[{cor1,cor2}];*)

Show[
ListPlot[Thread[{x1, y1}], Frame -> True,PlotStyle->Red] ,
]
]


I have started with some basic lines, which will generate some random points. Call the {x1,y1} dataset 1 and {x2,y2} the dataset 2.

I then want to Catch the two set when they have similar Correlation, for example, both are 0.43 to 2 decimal places, then plot them side by side.

Or -0.453 to 3 decimal places, then plot them side by side.

What's the best way to do it?

Thanks.

With[
{
decimals = 3,
length = 10,
range = 10
},
Block[
{
rcor = Round[Correlation[#[[All, 1]], #[[All, 2]]], Power[10, -decimals]] &,
ds1 = RandomReal[range, {length, 2}],
ds2 = RandomReal[range, {length, 2}],
corr
},
corr = rcor[ds1];
While[
corr =!= rcor[ds2],
ds2 = RandomReal[range, {length, 2}]
];
{ds1, ds2}
]]