Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Created December 24, 2018 15:12
Show Gist options
  • Save pervognsen/011673308f1e6b6c01487c475b262097 to your computer and use it in GitHub Desktop.
Save pervognsen/011673308f1e6b6c01487c475b262097 to your computer and use it in GitHub Desktop.
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