Created
October 10, 2016 00:56
-
-
Save bakkiraju/0bfaebaa46cc3920197fa99e5e29be9a to your computer and use it in GitHub Desktop.
Fisher-Yates shuffle
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(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