function value = randInt(min,max) % RANDINT Generate a random integer between MIN and MAX % Ensure that the input it legal: if ... ~isreal(min) | ~isreal(max) | ... % no complex isinf(min) | isinf(max) | ... % no infinite isnan(min) | isnan(max) | ... % no NaNs ~isnumeric(min) | ~isnumeric(max) | ... % no non-numerical values min > realmax | max > realmax | ... % lower bound of integer min < -realmax | max < -realmax | ... % upper bound of integer floor(min)~=ceil(min) | floor(max)~=ceil(max) | ... % no decimal/fraction values min > max % no flipflop of max/min error('You are trying to find an illegal random number!'); end value = floor(rand*(max-min+1)) + floor(min);