The Pseudorandom Rhythm Section

Last year RMITCS ran a Algorithmic SATB Composition Competition, to generate a SATB song from arbitrary text. I wasn’t able to get anything working for the competition, but I did learn a bit about generating and manipulating musical scores in Python.

I already had a random chord progression generator in my miscellaneous scripts repo. I tried playing around with using that to generate scores with harmonically pleasing chords. I didn’t have much luck with text analysis; the project shifted into attempt to do some kind of instrumental jazz/bebop generator.

The melody got dropped as well, and the result is the Pseudorandom Rhythm Section, which generates a random chord progression and piano/bass acompaniment. The output is a score in MusicXML with both parts and the chord symbols. Ideal for practicing improvisation or coming up with ideas for composition.



To generate the chord progression, PRRS puts a V7 and IMaj7 at the end and then works backwards, making a weighted random choice between chords that tend to resolve to the “current” chord. For example:

  1. I, _, _, V, I
  2. I, _, ii, V, I
  3. I, vi, ii, V, I

Then the actual notes are generated working forwards. First a duration is chosen for the current chord, then for each instrument a function is called to generate the part for that instrument until the next chord change. Chords that are more cadentially significant are more likely to have a longer duration.

The bass part is just a basic walking bassline up and down the chord notes. The piano plays the current chord using a random inversion (weighted in favour of the root inversion) and random note length and rests (weighted to rest more on the beat to syncopate off the bassline). There is also a special function for each instrument to do a random closing riff at the end of the song; currently this is just a random rhythm that is increasingly likely to hold the note for longer.


There’s example output (audio, PDF and Musescore) in the repo. The piano part jumps around way too much (currently it doesn’t make any attempt to flow smoothly between chords, just randomly tries any inversion) I may do something about that later.