This is my first try on algorithmic composition. Any critics and suggestions are welcome, because this really sounds like a bad composition. Please share your opinion, techniques and theories to me. I am still learning. Thank you.
#Algorithmic Tune #by Agustinus Cao #randomizing notes in C Major scale, without any of the #sharp notes, ranging from C3 to C5. Song length #is specified by songlen variable. Each note duration #is randomized from notesdur list. The duration of the #last note is determined by subtracting songlen by total #duration the notes. The composed tune is then played twice. notes = [0, :C3, :D3, :E3, :F3, :G3, :A3, :B3, :C4, :D4, :E4, :F4, :G4, :A4, :B4, :C5] notesdur = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] songlen = 16 #Must be multiples of 4 rndnotes =  rndnotesdur =  use_random_seed Time.now.to_i use_bpm rrand_i(60, 100) ttldur = 0 #Randomize (songlen/0.25).times do rndnotes.push(notes[rand_i(notes.length())]) rndno = rand_i(notesdur.length()) if ttldur + notesdur[rndno] < songlen ttldur = ttldur + notesdur[rndno] rndnotesdur.push(notesdur[rndno]) else rndnotesdur.push(songlen-ttldur) break end end rndarrlen = rndnotes.length() #Metronome sound in_thread do (songlen/4*2).times do play_pattern_timed [:a5, 0,0,0,:e5, 0,0,0,:e5, 0,0,0,:e5,0,0,0], [0.25], release: 0.25, amp: 0.1 end end #Playing the randomised composition in_thread do 2.times do n = 0 rndarrlen.times do if rndnotes[n]!=0 play rndnotes[n], release: rndnotesdur[n], volume: 0.5 end sleep rndnotesdur[n] n = n+1 end end end