function pv=uniperm(N,a,c,Cmax)
% This program generates a random purhcase vector according to uniform
% permutation method.  
%
% Inputs: N    - Sample size
%         a    - probability vector
%         c    - link costs
%         Cmax - total budget
% Output: pv - random purchase vector
%

m=size(a,2); pv=zeros(N,m);

for i=1:N
    e=rand(1,m); % generate uniform permutation
    [e1,I]=sort(e); 
    X=zeros(1,m); C=0; C1=0;
    for k=1:m
        C=c(I(k))+C1;
        if C <= Cmax                        % If C <= Cmax, decide whether to purchase link
            X(I(k))=(rand(1,1)<=a(I(k)));   % I(k); if not set X(I(k))=0.
        else
            X(I(k))=0;
        end
        C1=C1+X(I(k))*c(I(k));
    end
    pv(i,:)=X;
end