function [KB,p_atoms] = BR_rand_KB(n,m,k)
%

clauses = zeros(m,k);

done = 0;
count = 0;
while done==0
    samp = randperm(n);
    samp = samp(1:k);
    s = rand(1,k)<0.5;
    s = 2*s - 1;
    samp = samp.*s;
    if max(min((samp==clauses)'))==0
        count = count + 1;
        clauses(count,:) = samp;
        if count==m
            done = 1;
        end
    end
end

p_atoms = rand(n,1);
p_atoms = p_atoms/sum(p_atoms);

for c = 1:m
    KB(c).clauses = clauses(c,:);
    KB(c).prob = BR_prob_or_atom_probs(clauses(c,:),p_atoms);
end
