Skip to content

Instantly share code, notes, and snippets.

@Gk0Wk
Created July 23, 2021 15:38
Show Gist options
  • Save Gk0Wk/9d469dba30b7359e0b13ea5b58ba2907 to your computer and use it in GitHub Desktop.
Save Gk0Wk/9d469dba30b7359e0b13ea5b58ba2907 to your computer and use it in GitHub Desktop.
很平均的打乱,每一步都符合条件概率
def shuffle(lst):
for i in range(len(lst))[::-1]:
rand = random.randint(0, i)
tmp = lst[rand]
lst[rand] = lst[i]
lst[i] = tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment