3 ms·
There are actually four variants: • loop counts downwards vs upwards • the processed part of the array is a uniform sample of the whole array, or it is a segm
by fanf2 10mo ago
There are actually four variants:
• loop counts downwards vs upwards
• the processed part of the array is a uniform sample of the whole array, or it is a segment that has been uniformly shuffled
Knuth described only the downwards sampling version, which is probably why it’s the most common.
The variants are compared quite well on wikipedia https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
- possiblywrong 10mo agoIt's interesting that the two forward versions of the algorithm were added to Wikipedia just a few months ago. (The OP article is from 2020.)