Skip to content

Instantly share code, notes, and snippets.

@bakkiraju
Created October 10, 2016 00:56
Show Gist options
  • Select an option

  • Save bakkiraju/0bfaebaa46cc3920197fa99e5e29be9a to your computer and use it in GitHub Desktop.

Select an option

Save bakkiraju/0bfaebaa46cc3920197fa99e5e29be9a to your computer and use it in GitHub Desktop.
Fisher-Yates shuffle
import random
def shuffle(in_arr):
n = len(in_arr)
for i in range(n-1,-1,-1):
j = random.randint(0,i)
in_arr[i],in_arr[j] = in_arr[j],in_arr[i]
return in_arr
print(shuffle([22,55,33,11,44]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment