Barrios AI

Artificial Intelligence for Musicians

  1. Introduction
  2. Emergent Harmonic Structures | Software 1.0
  3. Pythagoras and the Music of the Spheres
  4. Building the Modes from Ancient Theory
  5. Harmonic Ratios in Nature and Music
  6. Musical Mathematics
  7. Exploring Chance and Randomness
  8. Statistics of Sound
  9. Software 2.0 | Deep Learning: Teaching Computers to See
  10. Software 2.0 | Deep Learning: Teaching Computers to Hear
  11. Software 3.0 | Generative AI: Teaching Computers to Read & Write
  12. Software 3.0 | Gemini Notebook as RAG

Chapter 6: Exploring Chance and Randomness

Free Preview

6.1 Embracing Randomness

Chance opens new musical paths. Iannis Xenakis, John Cage, and free-jazz players like bassist William Parker all used randomness, though in different ways. Free jazz leans on instinct; Cage and Xenakis built formal systems.

import random
random.seed(141)   # pinned so you can verify; delete for fresh chance

notes = ['C', 'D', 'E', 'F', 'G', 'A', 'B']
random_sequence = random.choices(notes, k=10)
random_sequence

6.2 Probability in Improvisation

Musicians can bias randomness with weights, nudging phrases toward certain notes or rhythms.

notes   = ['C', 'D', 'E', 'F', 'G', 'A', 'B']
weights = [0.2, 0.05, 0.2, 0.05, 0.05, 0.35, 0.1]   # a thumb on A, C, and E

random.seed(141)
random_sequence = random.choices(notes, weights, k=10)
random_sequence

Music can welcome chance.
This chapter shows how Xenakis, Cage, and free-jazz players used randomness, then lets you code aleatoric, stochastic, and algorithmic pieces in Python.

Continue reading this chapter

You're reading a free preview. Purchase the book to unlock every chapter in Artificial Intelligence for Musicians.

✓ Full book unlocked✓ Every chapter✓ Runnable code✓ Lifetime access

Want a hand with the code or building your own setup?

I'm an AI/ML engineer and a professional musician. Bring a question, a real project, a tool you wish existed, or a workflow that's eating your time, and we'll build it on your machine with your files. First call is free, 15 minutes, no commitment.

Book a free 15 minute call →