function rulenumberbinary=rulenumber_generator_percentage_background(inputvalue,occurancepercentage,possiblestates,rulecolors)
% This function generate random rules, then randomly replaces X percentage of the digits with the input value
% So your rule will have atleast 90% zeros if you want.
% Note: ATLEAST X%. It could easily have more.
% If the random rule generated is [1,1,1,1,1,1,1,1] the putting 10%=1 will
% be meaningless since they're all 1. This function cannot say make
% exactly X% 1 and the rest random from the remaining values.
%inputvalue=0; occurancepercentage=0.9;
%possible states is basically length of array, [0,rulecolors-1] says use numbers 0 thru rulecolors-1
rulenumberbinary=randint(1,possiblestates,[0,rulecolors-1])
rulenumberbinary(1,randint(1,round(possiblestates*occurancepercentage),[1,possiblestates]))=inputvalue