def symrand(dim_or_eigv):
if isinstance(dim_or_eigv, int):<EOL><INDENT>dim = dim_or_eigv<EOL>d = (rand(dim)*<NUM_LIT:2>)-<NUM_LIT:1><EOL><DEDENT>elif (isinstance(dim_or_eigv, ndarray) and<EOL>len(dim_or_eigv.shape) == <NUM_LIT:1>):<EOL><INDENT>dim = dim_or_eigv.shape[<NUM_LIT:0>]<EOL>d = dim_or_eigv<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>v = random_rot(dim)<EOL>h = dot(dot(v.T.conj(), diag(d)), v)<EOL>h = <NUM_LIT:0.5>*(h.T+h)<EOL>return h<EOL>
Return a random symmetric (Hermitian) matrix.

    If 'dim_or_eigv' is an integer N, return a NxN matrix, with eigenvalues
        uniformly distributed on (-1,1).

    If 'dim_or_eigv' is  1-D real array 'a', return a matrix whose
                      eigenvalues are 'a'.