function W = randomize(X1,Pd,teta,t)

N=10;                         % Number of the Antennas
% M=120;                        % Number of the directions
KK=1;
Pt=10^(-.692);
T = length(teta);
shift=0;


[u1,v1]=eig(X1);
root_mat=u1*v1.^(.5);
for shomara=1:1000
    disp(shomara)
%     Candidatewa=[];
    for lll=1:KK
        ran_vec=randn(N,1)+j*randn(N,1);
        ran_vec=ran_vec./abs(ran_vec);
        Candidatetemp=root_mat*ran_vec;
%       Candidatew=[Candidatew Candidatetemp];
    end
    for lll=1:N/2
        aaa=[Candidatetemp(lll) Candidatetemp(N-(lll-1))];
        Candidatetemp(lll)= Candidatetemp(lll,:)/norm(aaa)*sqrt(Pt/10);
        Candidatetemp(N-(lll-1))= Candidatetemp(N-(lll-1))/norm(aaa)*sqrt(Pt/10);
    end
% Candidatew=[Candidatew Candidatetemp];
%     for llla=1:KK
%         ran_vec=randn(N,1)+j*randn(N,1);
%         ran_vec=ran_vec./abs(ran_vec);
%         Candidatetempa=root_mat1*ran_vec;
%         Candidatewa=[Candidatewa Candidatetempa];
%     end
%     for llla=1:N/2
%         aaa=[Candidatew(llla) Candidatew(N-(llla-1))];
%         Candidatewa(llla)= Candidatew(llla,:)/norm(aaa)*sqrt(Pt/10);
%         Candidatewa(N-(llla-1))= Candidatewa(N-(llla-1))/norm(aaa)*sqrt(Pt/10);
%     end

    for ind1=1:T
%         temp(ind1)=abs(trace(matA(teta(ind1),N)*Candidatew*Candidatew')+trace(matA(teta(ind1),N)*Candidatewa*Candidatewa')-Pd(ind1)*t);
          temp(ind1)=abs(trace(matA(teta(ind1),N)*Candidatetemp*Candidatetemp') - Pd(ind1));
    end
    Val1=max(temp);
    if (shomara ==1)
        Val=Val1;
        Candidatefinal=Candidatetemp;
%         Candidatefinala=Candidatewa;
    else
        if ( abs(Val)- abs(Val1) > 0  )
            Val=Val1;
            Candidatefinal=Candidatetemp;
%             Candidatefinala=Candidatewa;
        end
    end
end
% W =[Candidatefinal conj(Candidatefinal(10:-1:1)) Candidatefinala conj(Candidatefinala(10:-1:1))]/sqrt(2)4
W =[Candidatefinal conj(Candidatefinal(10:-1:1))]/sqrt(2)
end

