4 ms·
I really like Floyd's algorithm for sampling n elements without duplicates in linear time. https://fermatslibrary.com/s/a-sample-of-brilliance https://fermatsl
by aurelian15 8y ago
I really like Floyd's algorithm for sampling n elements without duplicates in linear time.
https://fermatslibrary.com/s/a-sample-of-brilliance https://fermatslibrary.com/s/a-sample-of-brilliance
- justinpombrio 8y agoThat's a neat algorithm. You could also do part of a Fisher-Yates shuffle, if you're ok allocating the array.