function res = CS_EX1_small_rand(n,m,max_sent_len,num_trials,max_samps)
% CS_EX1_small_rand - Experiment 1 rand axis results on small solvable KBs
% On input:
%     n (int): number of atoms
%     m (int): max number of clauses
%     max_sent_len (int): max number of literals in clause
%     num_trials (int): number of trial KBs
%     max_samps (int): max number of random tries on a trial
% On output:
%     res (int): sample number where soution found; else 0
% Call:
%     res = CS_EX1_small_rand(10,20,5,10,10000);
% Author:
%     T. Henderson
%     UU
%     Fall 2022
%

TOL = 0.01;

%rng('default');
res = zeros(num_trials,1);
options = optimoptions('linprog','Algorithm','interior-point',...
    'Display','none');
for t = 1:num_trials
    OK = 0;
    while OK==0
        [KB,ccp] = BR_gen_test_KB_gen(n,m,max_sent_len);
%        [KB,ccp] = BR_gen_test_KB_ind(n,m,max_sent_len);
        if ~isempty(ccp)
            OK = 1;
        end
    end
    n = max(CS_vars(KB,[]));
    max_dist = sqrt(n-2)/2 + TOL;
    pc = 0.5*ones(n,1);
    xmin = zeros(n,1);
    xmax = ones(n,1);
    h = CS_KB2hp(KB);
    done = 0;
    count = 0;
    while done==0&count<max_samps
        count = count + 1;
        [t,count]
        dir = 0.5*ones(n,1) - rand(n,1);
        dir = dir/norm(dir);
        x = linprog(dir,-h(:,1:end-1),h(:,end),[],[],xmin,xmax,options);
        if norm(pc-x)>max_dist;
            res(t) = count;
            done = 1;
        end
    end
end

tch = 0;
