require 'optparse' options = { input: 'input', output: 'out', tracks: 40, generate: 0 } OptionParser.new do |opts| opts.banner = 'savage blind test generator' opts.on('-i', '--input=FOLDER', 'select input folder') do |i| options[:input] = i end end.parse! entries = [] Dir["#{options[:input]}/*.csv"].each do |path| entries.concat(File.readlines(path).select { |l| !l.start_with?('#') && !l.start_with?('!') }) end entries.shuffle! (0..options[:generate]).each do |index| File.open("#{options[:output]}/#{index}.csv", 'w') { |f| f.write(entries.sample(options[:tracks]).join('')) } end