Skip to content

Instantly share code, notes, and snippets.

@rishi93
Created September 23, 2015 06:52
Show Gist options
  • Save rishi93/b7dff93961899b8af4bf to your computer and use it in GitHub Desktop.
Save rishi93/b7dff93961899b8af4bf to your computer and use it in GitHub Desktop.
Fisher Yates Shuffling Algorithm
import random
def shuffle(arr):
for i in range(len(arr)-1,0,-1):
temp = random.randint(0,i) #random integer N such that 0<=N<=i
arr[i],arr[temp] = arr[temp],arr[i]
arr = [1,2,3,4,5,6]
shuffle(arr)
print(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment