Created
September 23, 2015 06:52
-
-
Save rishi93/b7dff93961899b8af4bf to your computer and use it in GitHub Desktop.
Fisher Yates Shuffling Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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