function A = projection_random_matrix ( n, k, key )

%*****************************************************************************80
%
%% projection_random_matrix() returns a random projection matrix.
%
%  Properties:
%
%    If k == n, det(A) = 1;  Otherwise det(A) = 0.
%
%    The only eigenvalues of A are 0 and 1.
%
%    A*A=A.
%
%    A is symmetric.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 May 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of A (default = 5 ).
%
%    integer K: the rank of the matrix.  (default = n-1);
%
%    integer KEY, a positive integer that selects the data.
%    (default = 123456789).
%
%  Output:
%
%    real A(N,N), the matrix.
%
  if ( nargin < 1 )
    n = 5;
  end

  if ( nargin < 2 )
    k = n - 1;
  end

  if ( nargin < 3 )
    key = 123456789;
  end

  rng ( key );

  V = rand ( n, k );

  A = V * inv ( V' * V ) * V';

  return
end

