Skip to content

Instantly share code, notes, and snippets.

@jdhao
Last active December 16, 2019 06:46
Show Gist options
  • Save jdhao/f534eda61235546ee7065b04690a2f5f to your computer and use it in GitHub Desktop.
Save jdhao/f534eda61235546ee7065b04690a2f5f to your computer and use it in GitHub Desktop.
There is a difference between random.choices() and random.sample() in Python

In python, random.choices() will select K items from a list with replacement, which means that there are may be duplicated items in the result list. If you want to select K random item from the list without duplication, you need to use random.sample() instead.

I wasted one hour debugging this issue and suddenly found the casue. Sad :[

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment