Skip to content

Instantly share code, notes, and snippets.

@wengkhing
Created November 4, 2014 08:54
Show Gist options
  • Select an option

  • Save wengkhing/eb6d1a93e6514059e81a to your computer and use it in GitHub Desktop.

Select an option

Save wengkhing/eb6d1a93e6514059e81a to your computer and use it in GitHub Desktop.
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