Created
November 4, 2014 08:54
-
-
Save wengkhing/eb6d1a93e6514059e81a to your computer and use it in GitHub Desktop.
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
| def shuffle(array) | |
| # Implement the shuffle method | |
| for i in 0..(array.length - 1) | |
| j = rand(i) | |
| array[j], array[i] = array[i], array[j] | |
| end | |
| array | |
| end | |
| # Driver code: | |
| sorted_array = (1..10).to_a | |
| # This should print a different sequence of numbers each time | |
| p shuffle(sorted_array) | |
| p shuffle(sorted_array) | |
| p shuffle(sorted_array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment