Q:

How to construct a 128x32 scrambled matrix?

How can I construct a scrambled matrix with 128 rows and 32 columns in vb.net or Matlab? 
Entries of the matrix are numbers between 1 and 32 with the condition that each row mustn't contain duplicate elements and rows mustn't be duplicates.

A:

This is similar to @thewaywewalk's answer, but makes sure that the matrix has no repeated rows by testing if it does and in that case generating a new matrix:
done = 0;
while ~done
    [~, matrix] = sort(rand(128,32),2);
    %// generate each row as a random permutation, independently of other rows.
    %// This line was inspired by randperm code
    done = size(unique(matrix,'rows'),1) == 128;
    %// in the event that there are repeated rows: generate matrix again 
end

If my computations are correct, the probability that the matrix has repteated rows (and thus has to be generated again) is less than 
>> 128*127/factorial(32)
ans =
  6.1779e-032

Hey, it's more likely that a cosmic ray will spoil a given run of the program! So I guess you can safely remove the while loop :-)

