while(1) {
int r = rand():
if (r < (RAND_MAX - (RAND_MAX % max))) {
return r % max;
}
}
}
for (i = 0; i < jumble.length; i++) {
int r = rand(i)
save = jumble[i]
jumble[i] = jumble[r]
jumble[r] = save
It's O(N) and it works every time. Super easy to remember if you code it a few times.