Sampling without replacement

updated:

Efraimidis-Spirakis algorithm

Reference:

Weighted random sampling with a reservoir - ScienceDirect

Algorithm

Implementation tips

Since can be arbitrarily large and cause overfloating, it would be preferred to transform by

The logarithmic transformation preserves the order . Thus, instead of using , we can use to find what indices to return.

Code