I talk about this in my maths teaching blog: see the "How Many Tunes" post at www.thewessens.net/blog

I used a very restricted musical space - just 2 bars, 12 notes (white notes from A below middle C to E an octave above), some constraints for musicality and restrictions on rhythm, and wrote a web app to explore (and listen to) the possibilities. It is at my website "The Mathenæum" at www.thewessens.net/maths and is called "Computer Composer". The blog post links to it as well.

It's a lot of fun, and quite incredible how many tunes are possible. Here's the conclusion from the blog:

Adding these together, we have a total of 22 059 rhythms (from 3 notes to 16 notes), leading to more than 50 000 000 000 000 000 tunes (that’s 16 zeroes — 50 quadrillion!). Including harmonies, we end up with a final number of 2 300 000 000 000 000 000 songs (2.3 quintillion). And remember, these are not just random arrangements, but we have used rules to greatly increase the chance of a resulting tune sounding musical (matching harmony, starting on C etc).

That’s a lot of tunes! A very lot. So many that it’s actually quite difficult to imagine, but this might help.

- If we were to only keep one in every million songs (assuming the others are too similar or not musically interesting) we would still have more than 2 trillion songs in total.
- If we started composing in this way the very instant the universe began, writing one song every second right up until now, we would still be less than 20% through all the possibilities!
- If we printed out all the songs in a line, each song taking up 15cm, the length of paper would go from Earth to Proxima Centauri (the nearest star after the Sun — about 4.23 light years away) and back more than 4 times. That’s about 36 light years.

Ken