Skip to content

Instantly share code, notes, and snippets.

@bstolte
Created April 18, 2014 00:45
Show Gist options
  • Save bstolte/11019237 to your computer and use it in GitHub Desktop.
Save bstolte/11019237 to your computer and use it in GitHub Desktop.
playlist = ['Black Dog', 'Four Sticks', 'Battle of Evermore', 'When The Levee Breaks', 'Stairway to Heaven', 'Rock-n-Roll', 'Misty Mountain Hop', 'Going to California']
def shuffle playlist
shuffled_list = []
while playlist.length > 0
rand_index = rand(playlist.length)
current_index = 0
new_arr = []
playlist.each do |item|
if rand_index == current_index
shuffled_list.push item
else
new_arr.push item
end
current_index = current_index + 1
end
playlist = new_arr
end
shuffled_list
end
puts shuffle(playlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment