Skip to content

Instantly share code, notes, and snippets.

@AndrewGuard
Last active January 1, 2016 01:29
Show Gist options
  • Select an option

  • Save AndrewGuard/8073627 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewGuard/8073627 to your computer and use it in GitHub Desktop.
# Destructive method
list_of_items = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z)
def shuffle(list_of_items)
randomly_ordered_list = []
until list_of_items.length == 0
random_number = rand(list_of_items.length)
removed_item = list_of_items.slice!(random_number)
randomly_ordered_list << removed_item
end
p randomly_ordered_list
end
shuffle(list_of_items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment