In mathematics, the simplest example of * Random Walk* is a random process along a one-dimensional plane of integers, starting at 0 and moving in the positive or negative direction in steps of +1 or -1, with equal probability. The

*theory has been applied in many domains including*

**Random Walk***and even the*

**Physics***.*

**Stock Market*** Here* is a nice article on the principle of

*in Mathematics. A more detailed video lecture is available*

**Random Walk***.*

**here**The following shows a rendering of the * Random Walk* process in

*.*

**Mathematica**My focus today is on using the * Random Walk* idea to generate music in

*, my preferred platform for algorithmic music composition.*

**Opusmodus***has many functions that help mimic randomness, and one such function is*

**Opusmodus***, an implementation of the*

**“gen-walk”***idea on a 1-dimensional plane.*

**Random Walk**The following shows three evaluations of the * “gen-walk”* function (executed in the

*pane):*

**Listener**The first example shows 10 successive integer values starting from 0 with steps of +1 or -1, with equal probability.

The second example shows how we can specify the step size. In this case, it can be +/-1, +/-2 and +/-3.

The third example is a very useful extension, where instead of working with integers, we work with pitches directly. In this case, we specify a starting pitch (on the chromatic scale) and let the function generate other pitches based on the given intervals. This is the idea that we will be using today.

It is also possible to specify the * forward* and

*probabilities. Please go through the documentation to understand its entire functionality.*

**backward**Just as I did in * Mathematica*, we can plot the generated integral values in

*. See this image:*

**Opusmodus**The above plot was generated by the following expression:

It is now time to look at the * Opusmodus* code for music generation:

The * “create-track”* function does the main work. First, we select the rhythm randomly from the given set. Then, required number of pitches are generated using the

*function. The number of pitches depends on the corresponding rhythm (we exclude rests). These two are then combined to create the*

**gen-walk***. Just to make it interesting, I am using three channels and each of then will be associated with a different*

**OMN***structure.*

**OMN**The generated music is far from perfect, of course. The idea is just to show how we can use * “gen-walk”* function to create music. One can apply other filters to come up with better music.

Note that every time we run this code, a different piece of music will be generated, and that is the idea! Here is the * musicxml* rendering during one execution of the above code:

Here is another run:

As you can see for yourself, a simple function such as * gen-walk* can lay the foundation for some interesting musical structure. You can use my code as a starting point and experiment further by adding your own logic.

You can download the * Opusmodus* code from

*. You can find my other articles on*

**here**

**Opusmodus***.*

**here**Have a nice weekend!

Excellent. I subscribe to your blog because I am an Ircam and Opusmodus Open Music user. Thanks.