Euclidean rhythms

Euclidean patterns app screenshot

Euclidean patterns

Last week I read a really interesting article about computer generated rhythms: “Generating African rhythms using the euclidean algorithm” on Ruin & Wesen’s website. Usually I’m not so impressed by generative and algorithmic music, but this formula gives some very cool results.

The formula is simple really. It’s an algorithm to distribute an amount of notes as evenly as possible over a period of time, where time is divided in equal parts. A very basic example: Say you have one measure of sixteen sixteenth notes and there are four notes to be played, then this is how those four notes would be equally distributed by the algorithm:

x . . . x . . . x . . . x . . .

A basic house or techno kick drum pattern. There’s four notes on sixteen steps, so the division is easy, 16 / 4 = 4. It gives you one note every four steps. But it gets more interesting when the numbers don’t divide so easily. Take five hits on sixteen steps. Then the pattern becomes more irregular:

x . . . x . . x . . x . . x . .

It’s these irregular patterns that create the best rhythms. Especially when several patterns are combined. In Ruin & Wesen’s article there’s a few audio examples and here’s a video on of a MiniCommand MIDI controller generating Euclidean rhythms on a Machinedrum.

The algorithm

The algorithm is very well explained in the article I mentioned, so I won’t repeat it here. There’s another article on the weblog of Robin Price which includes a Max/MSP example, there’s a Pure Data example by Dave Poulter as well as one in Java by Kristopher Reese.

Absolutely worth reading is the paper by Godfried Toussaint who as far as I know first recognized the connection between the Euclidean algorithm and musical rhythms. It’s downlaodable as a PDF: “The Euclidean Algorithm Generates Traditional Musical Rhythms”.

The Flash app

Get Adobe Flash player 

Download the full source code here.

This is a Flash app I made over the weekend to quickly try out combining rhythms. It’s by no means complete, but it does work:

  • To create a new pattern doubleclick somewhere in the lower panel. A basic sixteen step quarter note pattern appears where you clicked.
  • To edit the pattern doubleclick it’s center circle. A settings popup appears with sliders for pattern length and number of hits. Change these to quickly get a feel for how these Euclidean patterns work. The ‘Sound’ dropdown menu lets you select a different sample for the pattern to play.
  • Click and drag the center circle to move a pattern.
  • The controls at the top are obvious: Start / stop playback, adjust volume and change tempo (in beats per minute).

You will notice that when you create a new pattern while patterns are already playing, the new pattern is not synchronized. To synchronize all patterns stop and restart playback.

Euclid of Alexandria

Euclid of Alexandria

There’s a lot I should add to make this a complete app: An open and save option for pattern combinations and their settings, an option to load and use your own samples, basic sample editing like volume, speed and sample start adjustment and more pattern options. But the first thing I’d like to do is to add MIDI output. So I can use these patterns to drive music software like Ableton Live or hardware like my Machinedrum. It seems Java is the easiest way to write software that can use MIDI, so next I will be learning to program Java.



Coul’d you build a similar program, where non-euclidean patters could be added and mixed by clicking? Great job anyway!!

agen bola online,

Does your blog have a contact page? I’m having a tough time locating it but, I’d like to send you an e-mail.
I’ve got some suggestions for your blog you might be interested
in hearing. Either way, great website and I look forward to seeing it grow over time.


I spend hours in with DAW synths and drum machines trying to make beat patterns and this app speeds the process up by making everything feel much more natural than plotting midi notes into squares. I wish there was a DAW or two that was like this app.


awesome stuff. although already knowing some areas of this as an electronic music producer, i have to say that the flash app is brilliant and would love to see it as a workable midi for ableton. please send me an update if you get round to doing this as i would love a copy :)

Alex Fink,

Regarding ThomasR’s question, there’s actually a much simpler algorithm that accomplishes the same thing as Bjorklund:
in Euclid(m, n), there is a beat at step i if and only if (m*i) mod n < m.
No need for any recursion. (Okay, this changes the starting point of the rhythm, but that's of no consequence.)

Jilt van Moorst,

Hey Wouter,

cool to see you’re working with this algorithm too! I’m working on an Arduino version to live in my modular analog synth, will let you know when I make some progress..

groet, Jilt


@Sirsicksik: I’ve heard of synthedit. Sounds easy to work with. At the moment I prefer to program everything myself because I enjoy programming and learn a lot by writing these applications. And for me there is no need to get them done quickly.
But still, what you say about Synthedit sounds interesting and it might be a good way for me to do prototypes. Thanks for the info.


Nice one, I can also recommend the softwareprogram synthedit (demo is free and has almost no limitations except less presets..which you can go around haha) to build this kind of sequencers. I already made quite some based on waveform-functions (every sound has it’s own rhythm when slowed down, reading out peaks, zero-crossings or mids, or combining them) ,counting matrices, divisions, automatic-recording etc etc. The euclidian-rhythm-generator shouldn’t be too hard to reconstruct and you get easy access to midi implementation, modulation routing or maybe implementing more mathematical functions to be combined with the euclidian (what happens if you transform from one shape to the other?).

ok, to prove my point..I just made one within one hour… independent amount of steps (up to 64 right now) and independent gate-division: set amount of steps independent from the squence itself for small offsets and amount of steps between each step (being rounded off to fit into the 64-step sequence). With some easy adds I can also add seperate counters with independent tempo adjusts and play-direction for each sequence. XD if you want some info/ideas/help, just contact me..I suppose you can see my e-mail..otherwise, leave a message and I’ll probably get a notice…

Per Karlsson,

Thank you for a great application
I am trying to figure out how to get Flash to play sounds in that kind of exact sync that I hear in your app. The problem is that I get completly lost in the code. Do you have a suggestion on where to find the methods timing sound and triggering sound?

Best regards
Per Karlsson

Phoebe Jiang,

Awesome article and app! I have fun playing around with the flash! It’s really useful and necessary to put an app on it so people will have a better understanding of Euclidean rhythm. I’ve never thought that it would be so beautiful when math and music are combined.


This is really interesting stuff

I’ve been working on some stuff recently involving non-standard pattern lengths and cross-rhythms (among other things) as its basis, though I’ve been using the Nord Modular G2, so it’ll be interesting to see if I can build something in the G2 environment which will generate these rhythms… should be possible. Good work!

If anyone’s interested, here’s a couple of the tunes I’ve done- it’s certainly in a similar sort of area


@Tony: That’s something I hope to add in the future. Send MIDI clock or follow incoming MIDI clock. Or both ideally of course.


It would be cool if the tempo could be slaved to incoming midi clock events. Now the solution would be using 120 bpm in both, your java application and the DAW, e.g. Ableton Live, then later controling tempo in Live via midi clock.

Euclidean MIDI Patterns,

[…] MIDI Patterns By Wouter | Published: May 22, 2011 ScreenshotIn January I posted a Euclidean rhythm generator in Flash. Polyrhythms generated by a mathematical algorithm. I wanted […]

Euclidean rhythms update,

[…] rhythms update By Wouter | Published: May 20, 2011 E(5, 13) patternThere’s an error in the Euclidean rhythms generator I posted in January. A few days ago I got a comment by Thomas pointing out the app generates wrong […]


Hi Thomas,
Yes you’re right. I never noticed this, but it is wrong indeed. Euclid(5, 13) should go like this:
So it looks like the algorithm stops one iteration too early. I’ll see if I can fix the error. Thanks for noticing!


Hey wouter,
a very brutal question:
are you sure this is a correct implementation of the algorithm?
citing from the article:
For example E(5; 13) = [1001010010100].

where the “small” [10] and “big” [100] are distributed evenly

but in the (very beautiful!) applet, having 5 fills in 13 steps returns [1001001001010]

(where the “small” fragments [10] are distributed next too each other at the end, and the “big” fragments [100] distributed together at the beginning…)

please correct me if i’m wrong! – The Bjorklund Algorithm,

[…] This is an excerpt from the somewhat melodramatically titled paper, The Euclidean Algorithm Generates Traditional Musical Rhythms. In short, sequences generated by the equal spacing algorithm described resemble various traditional rhythms, or otherwise sound pretty good. Create Digital Music did a post on various musical applications of it recently, like this neat little sequencer in flash. […]


Thanks! Yes, Java is easier than I thought it would be. Or at least it’s easy to get started. I like it. At the moment the GUI stuff takes most time to get used to; Swing component layout and screen repaints. And Threads are a new concept for me.

Karl Macklin,

Hey, just wanted to chime in and say that this is awesome!
Great work (both of you)!
Have fun learning Java, it’s not that different from AS3 so you wont have any trouble.


Hi Kristopher,

Thanks for your comment. Although I’m not sure I understand all you write, I think it’s about an algorithm that takes a combination of several of these polyrhythms and lets them evolve so they together form a more complex combined rhythm. A combination that isn’t random but where the rhythms grow together in a meaningful way according to the algorithm. That would be very interesting to hear and to know about.

And thanks for your offer of help on the Java MIDI API. The MIDI side of Java doesn’t give me too many problems at the moment. I find the graphics and GUI programming takes the most time to get used to. And I need to learn more about Threads. But in general learning Java as a Flash developer is a lot easier than I thought it would be.

It would be great if we could collaborate on a future project. I hope there will be an occasion to do so.

Kristopher Reese,


Thanks for the linkback to my post. Nice article as well. The flash app is nicely done, and extremely useful in hearing the combinations of these derived Euclidean Rhythms. Something I hadn’t considered doing myself- although I’m not really a drummer (I’m a saxophonist). Makes for an interesting concept of possibly changing these combined, complex rhythms into something closely related using genetic algorithms, which might provide a means for creating even more rich rhythms using this Euclidean ideology. I might have to play around with the idea some this weekend.

Let me know if you need any help with the Java MIDI API, I’ve spent a while learning it for another music related project (Generating Tonal Harmonic Progressions using Reinforcement Learning). I’d love to collaborate with you on some projects at some point; Its always nice to find people with the same interests in electroacoustics (although I am more on the side of computationally generated music). Still might lead to some interesting ideas…

Leave a Reply

Your email address will not be published. Required fields are marked *

eight + thirteen =