function a=perm(n)
	% a=perm(n). perm returns a random permutation matrix of
	% order m

  S = 1:n;  % start with a nice row; we will permute this row

  out = [];
  _n = n;  % we are destroying the value of _n 

  while _n>1,
    index_from_S = ceil(rand(1,1)*_n);  % select a random number 1..n
    out = [out, S(index_from_S)];   % enter in row matrix out the element
	                                  % from S at that position

    S = [S(1:(index_from_S-1)), S((index_from_S+1):_n)];
          % take that element out of S
    _n = _n-1;    % now, the size of S is one less
  end;

  out = [out, S(1)];  % now out contains the elements of S permuted randomly

  a = eye(n,n)(:,out);
    % select columns of identity matrix according to 'out' and assemble
    % them into a
endfunction
