Click the "Generate" button to create a brand new song! The program has analyzed thousands of tunes. When you run it, it starts with four random notes, then picks a new note probabilistically based on how often that note follows the last four in the sample. This is an example of the Markov chain technique for generating random texts.
The code is based on Daniel Shiffman's Markov example, but does some new things. Most notably, I use two independent Markov processes, one for pitches and one for durations. This has some benefits for the speed of the program, but also influences the music that comes out. Discussion questions: to what extent can you (a person) predict the next note in a song? What if you just know the last few pitches (like "C D E")? What if you just know the last few durations (like "quarter quarter eighth")? Does it matter what style of music you're listening to?
You can choose from four different robot brains: