Ignoring that some of the variables don't match up properly (the arrays: card and Card), it seems like the explanation of the first flaw may also be flawed.<p><i>Flaw #1: An Off-by-One Error<p>The algorithm above tries to iterate over each card in the deck, swapping each card with another randomly chosen card in the deck. However—every programmer has made this mistake before—there's an off-by-one error. The function random(n) returns a number between 0 and (n-1), not between 1 and n as the programmer intends. As a result, the algorithm will never swap the 52nd card with itself; the 52nd card can never end up in the 52nd place. So that is the first reason the "random" card shuffling isn't really random.</i><p>The comment refers to the Pascal code:<p><pre><code> random_number := random(51)+1;
</code></pre>
If the programmer really thought that random was between 1 and n then the random_number variable would be a number between 2 and 52 (1+1 to 51+1). It seems like, instead, a better explanation is that they may have thought random(n) produced a random number between 0 and n, hence the need to increment by one. Another explanation is they just messed up the slicing using 51 instead of 52.<p>The point being that in the writer's explanation of the flaw they actually make the same mistake.<p>Funnily enough googling "pascal random" points to a stackoverflow article where the best answer makes the same error.<p><a href="https://stackoverflow.com/questions/4965863/how-to-get-a-random-number-in-pascal" rel="nofollow">https://stackoverflow.com/questions/4965863/how-to-get-a-ran...</a>