Markov-Chain Melodies: How Simple Probability Writes Tunes

One of the earliest computer methods for generating melodies is also one of the simplest. A Markov chain is a model that chooses the next event based only on the current event, or on a few recent ones, using probabilities learned from examples. In music, it can be trained on a set of melodies and then asked to produce new ones that sound similar in their note-to-note movement. Understanding Markov chains helps learners see how pattern-based generation works and why more advanced systems were developed.
Counting what comes next
Imagine analysing a collection of simple folk tunes. For each note, you count which notes follow it. You might find that after C, the next note is D forty percent of the time in this collection, E thirty percent, G twenty percent and C again ten percent. These counts become a table of probabilities, known as a transition table.
To generate a new melody:
- start on a chosen note, such as C
- look up the probabilities for what follows C
- choose the next note randomly according to those probabilities
- repeat from the new note
The result is a sequence that reflects the step patterns of the training melodies.
Orders of memory
A first-order Markov chain looks only at the current note. A second-order chain looks at the last two notes, a third-order chain at the last three, and so on. Higher orders capture longer patterns, producing melodies that sound more like the training examples. But they also need more data, and if the order is too high, the model may simply copy long passages from the originals rather than creating something new.

Rhythm and other features
Early experiments often generated pitch and rhythm separately, or combined them as pairs. More detailed models include note duration, position within the bar or even chord context. Each added feature makes the output more musical, but also increases the amount of data needed.
You've read 32% of this article
Log in for free to read the remaining 68%
- Free to use
- No credit card needed
Plus, try Premium free for 7 days in the TIGA ALPHA app.
Continue with Google Sign up free Already a member? Log inStrengths of Markov melodies
Local smoothness
Because each note follows patterns from real music, short fragments often sound natural.
Style imitation
A model trained on one style, such as simple folk songs, produces melodies with similar intervals and contours.
Transparency
The transition table can be inspected and explained, making the model easy to understand and teach.
Weaknesses
The main weakness is lack of long-term structure. A Markov chain has no idea of phrases, repetition or a destination. Its melodies tend to wander, rarely returning to a theme or building to a climax. They may also end at random rather than on a satisfying cadence. Human music relies heavily on repetition and development across many bars, which a short memory cannot capture.
How later systems addressed the problem
Researchers tried many solutions: adding rules for phrase endings, combining Markov models with grammars, or constraining generation to fit a chosen harmony. Later, neural networks with longer memory and attention mechanisms were developed to capture structure across larger spans. Even so, Markov chains remain useful as teaching tools and as building blocks in some interactive music software.
A classroom experiment
Teachers can demonstrate the idea without a computer. Take a short melody that students know and count note-to-note transitions on a whiteboard. Then use numbered cards drawn from a bag to generate a new melody from the table. Play it on the piano and discuss: does it sound like the original style? Where does it lose direction? This activity connects probability, listening and composition.
Why this matters for learners
Understanding how simple models generate music helps students approach AI tools critically. They can recognise that a generated melody may be locally convincing but structurally weak, and that composers still shape form, repetition and meaning. This knowledge also helps learners use generative tools creatively, as a source of ideas rather than a finished product.
Learners using TIGA ALPHA can play classroom-generated Markov melodies and add their own endings, practising how to turn a wandering line into a satisfying phrase.
FAQ
Q: What is a Markov chain in music?
A: A model that chooses each next note based on probabilities learned from how notes follow each other in examples.
Q: Why do Markov melodies wander?
A: They remember only a few recent notes, so they lack phrase structure and a sense of direction.
Q: What does a higher order mean?
A: The model considers more previous notes, capturing longer patterns but needing more data.
Q: Are Markov chains still used?
A: Yes, especially as teaching tools and in some interactive or rule-based music systems.
Get started with TIGA ALPHA
TIGA ALPHA is an AI piano teaching app built by a Thai team, with lessons in 10 languages: Thai, English, Mandarin, Arabic, Japanese, Russian, Spanish, French, Hindi and Korean. Its CEO, Teacher Aum, has 20 years of experience in piano teaching, and that music teaching background shapes every lesson, while piano teaching with AI gives you feedback each time you play piano. Use it as an online piano lessons app for short daily sessions, follow it as a complete AI online piano course, or combine it with a piano course or piano learning course led by a teacher. Whether you want to learn piano from zero, learn piano online after a long break, learn music alongside your children or simply play music for fun, this online piano teaching application keeps your next step clear. New users get a 7-day free Premium trial, then US$24.99/month. Open the piano teaching app below and pick a first lesson that fits your week.
- Download and start: TIGA ALPHA landing page
- In-person lessons in Thailand: TIGA Studio
- About the company: tigaalpha.com
A Markov chain hears only a step or two at a time, and that short memory explains both its charm and its tendency to wander without a destination.