Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2014 11:50
Show Gist options
  • Save anonymous/8315732 to your computer and use it in GitHub Desktop.
Save anonymous/8315732 to your computer and use it in GitHub Desktop.
music_names = Dir['*.{mp3}']
def call_shuffle playlist
playlist_shuffle playlist, []
end
def playlist_shuffle playlist, shuffled_playlist
length = playlist.length
number = rand(length)
song = playlist[number]
shuffled_playlist.push song
playlist.delete_at(number)
return shuffled_playlist if playlist.empty?
playlist_shuffle playlist, shuffled_playlist
end
playlist = call_shuffle music_names
puts playlist
filename = 'playlist.txt'
playlist.each do |song|
File.open filename, 'w' do |f|
f.write("#{song}")
f.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment