Created
December 24, 2018 15:12
-
-
Save pervognsen/011673308f1e6b6c01487c475b262097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample(xs, k): | |
n = 0 | |
ys = k * [None] | |
for x in xs: | |
n += 1 | |
i = randrange(n) | |
if i < k: ys[i] = x | |
return ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment