function a = spd_random_matrix ( n, key )

%*****************************************************************************80
%
%% spd_random_matrix() returns a random symmetric positive definite matrix.
%
%  Discussion:
%
%    The matrix returned will have eigenvalues in the range [0,1].
%
%  Properties:
%
%    A is symmetric: A' = A.
%
%    A is positive definite: 0 < x'*A*x for nonzero x.
%
%    The eigenvalues of A will be real.
%
%    Generally, A is not diagonally dominant.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 May 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the order of A.
%
%    integer KEY, a positive value that selects the data.
%
%  Output:
%
%    real A(N,N), the matrix.
%

%
%  Get a random set of eigenvalues.
%
  lambda = rand ( n, 1 );
%
%  Get a random orthogonal matrix Q.
%
  q = orthogonal_random_matrix ( n, key );
%
%  Set A = Q * Lambda * Q'.
%
  a = zeros ( n, n );

  for i = 1 : n
    for j = 1 : n
      a(i,j) = 0.0;
      for k = 1 : n
        a(i,j) = a(i,j) + q(i,k) * lambda(k) * q(j,k);
      end
    end
  end

  return
end
