Here's an attempt at a summary of the LinearShuffle page. There's lots more discussion on that page, but much of it is redundant and needs to have RefactorMercilessly applied to it. In short, the objective is to take an array and shuffle it in linear time. Here's an obvious algorithm that's wrong: '''Icon:''' procedure shuffle(x) every !x :=: ?x return x end '''C:''' void shuffle(int *x, int n) { int i; for (i=0;i1;n--) swap(x,rand(n),n-1); } I've deliberately left the proof of the algorithm as a clear indication rather than a laborious step-by-step formal verification to show how a mathematician thinks about proofs. The code needs to be checked against the definition of the algorithm. In all the above, ''rand(j)'' is assumed to return a uniformly distributed random number from ''0'' to ''j-1'' inclusive. Yes, we could pass in '''void *''' and a '''swap''' function making this effectively polymorphic but this version works on '''int'''s for simplicity. Question: How would you write UnitTest''''''s for the above routines? ---- To avoid rehashing the same arguments over and over on this page, please add discussion below after reading LinearShuffle. * ''Correction made to the forward version where there was an off-by-one error. Analyzing the case where n == 2 shows the current version to be correct. Kudos to the person who found the error - how long has this code been here without anyone bothering to check it?'' * ''Correction made to the backwards version where the evaluation of parameters in a function call was undefined. More kudos due.''