Created
January 8, 2014 11:50
-
-
Save anonymous/8315732 to your computer and use it in GitHub Desktop.
This file contains 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
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