Here's another approach, using randperm and dec2base without the overhead of memory to create all possible strings (citing Luis solution ) -
%// Inputs start = 1 stop = 5 Nr = 10 %// Number of rows needed Nc = 2 %// Number of cols needed intv = stop - start + 1; %// Interval/range of numbers rand_ID = randperm(power(intv,Nc)-1,Nr); %// Unique IDs out = dec2base(rand_ID,intv) - '0'+ start %// 2D array of unique numbers
Run Examples -
Case No. 1 (the same parameters as indicated in the question):
start = 1 stop = 5 Nr = 10 Nc = 2 out = 1 3 2 1 5 3 5 4 5 5 3 4 2 3 2 5 3 3 1 4
Case No. 2 (different parameters):
start = 1025 stop = 1033 Nr = 10 Nc = 5 out = 1030 1029 1033 1028 1029 1033 1029 1026 1025 1025 1028 1026 1031 1028 1030 1028 1031 1027 1028 1025 1033 1032 1031 1029 1032 1033 1029 1030 1027 1028 1031 1025 1032 1027 1025 1033 1033 1025 1028 1029 1031 1033 1025 1033 1029 1028 1025 1027 1028 1032
Divakar
source share