function a = permutation_random_matrix ( n, key )

%*****************************************************************************80
%
%% permutation_random_matrix returns the PERMUTATION_RANDOM matrix.
%
%  Example:
%
%    n = 5, key = 123456789.
%
%     0     1     0     0     0
%     0     0     0     0     1
%     1     0     0     0     0
%     0     0     1     0     0
%     0     0     0     1     0
%
%  Properties:
%
%    Generally, A is not diagonally dominant.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 October 2007
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Albert Nijenhuis, Herbert Wilf,
%    Combinatorial Algorithms,
%    Academic Press, 1978, second edition,
%    ISBN 0-12-519260-6.
%
%  Input:
%
%    integer N, the order of the matrix.
%
%    integer KEY, a positive value that selects the data.
%
%  Output:
%
%    real A(N,N), the matrix.
%
  rng ( key );

  p = i4vec_indicator ( n );

  for i = 1 : n
    j = randi ( [ i, n ], 1 );
    temp = p(j);
    p(j) = p(i);
    p(i) = temp;
  end

  a = perm_vec_to_mat ( n, p );

  return
end
