Thank you for the information. Perhaps I should have made clearer in that my encounter with this algorithm, which motivated the whole write up, was in research-oriented/scientific code in which it was being used to sample permutations of an array uniformly at random. My contention is that this is a misuse of this algorithm, because it does not sample the space of permutations uniformly.
But in light of what you write about the algorithm's standing and pedigree, the title of my meditation is an awful one. Maybe the whole node should be retracted for the sake of not confusing others. Let me know what you think.
Update: I found a version of Fisher-Yates online (linked from here):
#include <stdlib.h>
void shuffle(int *array, size_t n) {
if (n > 1) {
size_t i;
for (i = 0; i < n - 1; i++) { /**/
size_t j = i + rand()/(RAND_MAX / (n - i) + 1); /**/
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
This is equivalent to the algorithm used by my
random_perm, not the one used by
naive_shuffle. To get the latter algorithm, the lines indicated with /**/ above would have to be changed to:
for (i = 0; i < n; i++) {
size_t j = rand()/(RAND_MAX / n);
the lowliest monk