MATLAB: How to define a 1×3 array with “unifrnd” while second element must always be greater than first one

random number generator

I wanna use "unifrnd" command to produce a 1×3 array but conditionally I need the second element of the array to be always greater than the first element. Considering the example below: >> min=0; max=10; A=unifrnd(min,max,1,3)
A = 6.3 6.0 0.4
Now, How can I make it to select the second element always greater than first one.
Thanks,

Best Answer

minvals = min(A(:,1:2),[],2);
maxvals = max(A(:,1:2),[],2);
A(:,1) = minvals;
A(:,2) = maxvals;
Related Question