function A = randspd(s)
% RANDSPD : Random symmetric matrix with specified eigenvalues
%
% A = randspd(s)
%       s:  n-vector of desired eigenvalues (positive for SPD matrix)
%       A:  n-by-n symmetric dense matrix with eigenvalues s

if min(size(s)) > 1, error('input s must be a vector'), end;

n = length(s);
S = diag(s);
[Q,R] = qr(randn(n));  % create random orthogonal matrix for eigenvectors
A = Q*S*Q';