function [carta,mf] = funCartas_JMS(mi,replace)
% Draw function for problem 3 of control 3.
% J.M.Soler, May.2022
% Input:
%   mi(n)   : initial deck state for n cards (0|1) => card (present|absent)
%   replace : replace drawn card?
% Output:
%   carta  : drawn card
%   mf(n)  : final deck state

c = find(mi);            % cards present in deck
ic = randi(numel(c));    % index of randomly drawn card
carta = c(ic);           % drawn card
mf = mi;                 % final deck
if ~replace
  mf(carta) = 0;
end

end
