function [output_val,output_tally]=onedim_randomizer(possible_matrix,tally) %this function, receiving a range of possibilities and a tally of how those possibilities have been used thus far, randomly finds %a new possibility each trial st the choice is from among those that at the time of the trial have not chosen any more than any other possibility num_possibilities=possible_matrix(1); if ~(length(max(tally))) output_tally=zeros(1,num_possibilities); %this prevents the situation where on the first trial the first possible value is chosen and the min of tally is 1, rather than zero na=rand*num_possibilities; na=ceil(na); output_tally(na)=1; else ca_before=min(tally); ca_after=ca_before-1; while ca_before~=ca_after na=rand*num_possibilities; na=ceil(na); ca_after=tally(na); %escape the while loop if the randomly generated value's spot in the tally matrix has the same value as the min of the tally matrix end output_tally=tally; output_tally(na)=output_tally(na)+1; end ba=na-1; %correcting for indexing above_min=ba*possible_matrix(3); output_val=above_min+possible_matrix(2);