I need something similar to the List below, but not totally random and values within each individual column and row remaining the same:

xyCoord = RandomReal[{-2, 25}, {270, 219, 2}];

The above is not what is required. I need

{{x1, y1}, {x1, y2}.........{x1,y219}}, {{x2, y1,}, {x2, y2}.........., {x2, y219}},..............,{{x270, y1},.........................,{x270, y219}}

I need x1 > x2> x3...... > x270. Same for y need y1 > y2 > y219.

Each xi and yi (i being index number) is selected randomly within these constraints.

The final list should have the following dimensions.....

Dimensions[xyCoord] = {270, 219, 2}
  • $\begingroup$ Do you want a sorted list as already provided, or do you want the random number generated at each step to be generated in the range {lastX, 25}? i.e. do you want xcoord =Flatten@NestList[ RandomReal[{Last@#, 25}, 1] &, {-2}, 270] similarly for y, then proceed as JasonB suggested. $\endgroup$
    – N.J.Evans
    Commented May 13, 2016 at 16:24

2 Answers 2


Your command will generate 270*219*2 = 118260 random numbers, but from your description, you only want 270+219 random numbers. This should work,

xcoord = RandomReal[{-2, 25}, 270];
ycoord = RandomReal[{-2, 25}, 219];
xycoord = Outer[List, Reverse@Sort@xcoord, Reverse@Sort@ycoord];

Here is an example output if I change the 270 and 219 to 10 and 10

Mathematica graphics

  • $\begingroup$ Tuples[] seems like a better choice here. $\endgroup$ Commented May 13, 2016 at 14:03
  • $\begingroup$ You mean like Tuples[{Sort@xcoord, Sort@ycoord}]? But then you would need to use Partition to shape it into a three-dimensional array right? $\endgroup$
    – Jason B.
    Commented May 13, 2016 at 14:08
  • $\begingroup$ Huh, I didn't notice that the OP wanted a nested list. Sorry 'bout that... $\endgroup$ Commented May 13, 2016 at 14:09
xcoord = Reverse@Sort@RandomReal[{-2, 25}, 270];
ycoord = Reverse@Sort@RandomReal[{-2, 25}, 219];
Table[{x, y} , {x, xcoord}, {y, ycoord}]

Another way is this (as mentioned in comments):

Partition[ Tuples[{xcoord, ycoord}] , Length@ycoord]

which is useful to know especially if you want to flatten the list anyway you can just use Tuples[{xcoord, ycoord}]

  • $\begingroup$ Well done. Good Answer. Although, you forgot the sort@ on the ycoord. $\endgroup$
    – SPIL
    Commented May 13, 2016 at 15:06
  • $\begingroup$ oops, fixed.... $\endgroup$
    – george2079
    Commented May 13, 2016 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.