Consider this code to simulate a simple instance of the coupon collector problem. We initialize an array to {0, 0} and then keep incrementing a random element until we've incremented every element at least once.
ch = ConstantArray[0, 2];
While[Min[ch] === 0,
i = RandomInteger[{1, 2}];
ch[[i]]++];
ch
It returns something like {1, 1} or {3, 1}. The smallest element will necessarily be 1 because the while-loop terminates as soon as any element in the array is greater than zero.
Now suppose we decide to condense the body of the while-loop into one line:
ch = ConstantArray[0, 2];
While[Min[ch] === 0,
ch[[RandomInteger[{1, 2}]]]++];
ch
Everything seems ok, but then, horror: sometimes it returns things like {2, 3} where neither element is 1.
How can that happen?
PS, in case it gives anyone any ideas, here's a more definitive demonstration of how the above bits of code give different results:
n = 200;
ch = ConstantArray[0, n];
While[Min[ch] === 0,
i = RandomInteger[{1, n}];
ch[[i]]++];
ch2 = ConstantArray[0, n];
While[Min[ch2] === 0,
ch2[[RandomInteger[{1, n}]]]++];
ListPlot[{Sort@ch, Sort@ch2}, PlotStyle->{PointSize[.015], Automatic}]

RandomIntegerbefore and then use its result, it works. $\endgroup$SeedRandom[3]; ca = {a, b}; ca[[RandomInteger[{1, 2}]]]++; caThat bizarrely returns {a, 1+a}. $\endgroup$