News for hackers. Stuff that matters.
Re:Vitter's reservoir sampling algorithm D: randomly selecti... by jdfr on Monday April 04, 2016 @03:04AM (#11419918)
Vitter's algorithm is for when you need to generate a random list of unique items with sequential reads. If you drop that requirement, you can just use a substitution-permutation network: https://en.wikipedia.org/wiki/Substitution-permutation_netwo...

A SPN will generate a unique random permutation, from which you can draw your random list of unique items. With a little of post-ptocessing, you can generate random permutations of arbitrary size.

I have implemented it in matlab and python:

http://nl.mathworks.com/matlabcentral/fileexchange/36626-alg...

https://gist.github.com/jdfr/46633c630471494d67ae

There are no comments on this comment yet.