% You have a sack of nine balls, three each red, green, blue. % If you draw two balls out of the sack, what's the chance they are % both green? Ntrials = 1000; % number of trials r = 0; g = 1; b = 2; sack = [r r r g g g b b b]; Nballs = length(sack); count = 0; for n=1:Ntrials draw = sack(randperm(9)); count = count + (sum(draw(1:2) == [g g]) == 2); % If Matlab were a real programming language, it would accept % count = count + (sum(sack(randperm(9))(1:2) == [g g]) == 2); end fprintf('The prob of choosing two green balls first is %f\n', count/Ntrials);