This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients mark.dickinson, rhettinger, serhiy.storchaka, thomasahle
Date 2019-07-25.17:50:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564077006.47.0.456295959046.issue37682@roundup.psfhosted.org>
In-reply-to
Content
Possible implementation:

from itertools import islice as _islice

def reservoir_sample(self, population, k):
    if k < 0:
        raise ValueError("Sample is negative")
    it = iter(population)
    result = list(_islice(it, k))
    if len(result) < k:
        raise ValueError("Sample larger than population")
    self.shuffle(result)
    randbelow = self._randbelow
    for i, x in enumerate(it, k+1):
        j = randbelow(i)
        if j < k:
            result[j] = x
    return result
History
Date User Action Args
2019-07-25 17:50:06serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, mark.dickinson, thomasahle
2019-07-25 17:50:06serhiy.storchakasetmessageid: <1564077006.47.0.456295959046.issue37682@roundup.psfhosted.org>
2019-07-25 17:50:06serhiy.storchakalinkissue37682 messages
2019-07-25 17:50:06serhiy.storchakacreate