# Specifying range in RandomReal

Is it possible to define the specific range of a RandomReal array for each coordinate? For example, the code

x = 1; y = 10; L = 20;
{RandomReal[x, L], RandomReal[y, L]} // Transpose


Gives me a list of 20 pairs where the first coordinate is a random real between 0 and 1, and the second is a random real between 0 and 10.

I suspect there is a neater way of writing this. Any ideas?

• I don't think there is. You can use RandomPoint and Rectangle but it is not really any more concise. – Szabolcs Jan 13 at 14:58
• I see. Thanks a lot! – sam wolfe Jan 13 at 14:59
• One can come up with variations on your version, but I don't think they're really better. E.g. Transpose[{1, 10} RandomReal[1, {2, 20}]] – Szabolcs Jan 13 at 15:01

Not with RandomReal that I know of, but you can define a UniformDistribution with your required limits and draw samples from it using RandomVariate:

pts = RandomVariate[UniformDistribution[{{0, 1}, {0, 10}}], 20]


Check that it works as expected:

MinMax /@ Transpose@pts


{{0.00103093, 0.996982}, {0.530043, 9.94596}}

Just marginally faster

x = 1; y = 10; L = 20;
Transpose[{RandomReal[x, L], RandomReal[y, L]}]; // RepeatedTiming


{4.2*10^-6,Null}

ReIm@RandomComplex[{0, x + I y}, L]; // RepeatedTiming


{2.5*10^-6,Null}

Marco's solution is the best way to do this. An alternative procedure is to use RescalingTransform[] on RandomReal[], like so:

RescalingTransform[{{0, 1}, {0, 1}}, {{0, 1}, {0, 10}}][RandomReal[1, {20, 2}]]