function B=genq(v,n)
% generate an outcome based on probabilities v
% where v is an nxn matrix of probs.
% note: we require one queen per row
% each row of v MUST sum to > 0
Z=zeros(n);B=Z;
r=rand(n,1);
if mod(n,2)==1, %odd
    h=(n-1)/2;
else
    h=n/2;
end
for i=1:n, % see where to add the next queen
    for j=1:n,
        Z(i,j+1)=Z(i,j)+v(i,j);
        if ((Z(i,j)<=r(i)) && (r(i)<Z(i,j+1))),
            if((i==1)&&(j>(ceil(n/2)))),
                B(i,j-h)=1;
            else
                B(i,j)=1;
            end
        end
    end
end