MATLAB: Generate ‘k’ vectors of unique (non-repetitive) integer random variables in the same range

random integers

How can I generate two vectors of unique (non-repetitive) integer random variables (each vector with 50 components) in the range of [-80, 80]? What I wrote so far is this:
a = -80;
b = 80;
A = round((b-a).*rand(50,1) + a);
B = round((b-a).*rand(50,1) + a);
I need that the elements in A and B are unique, i.e., no element of A is in B, and reverse! But I don't know how to do that!

Best Answer

There's no guarantee that successive calls to randperm will not create repetitions (after all after a while it would have to anyway), so use simply one call, and split it in two:
v = randperm(100, 90);
A = v(1:50); B = v(51:end);