# Max Tutorial #9: Making Music with Randomness

This tutorial is a brief introduction to making music using randomness. First of all, it cannot be overstated that there are many different ways to use randomness to make music, and each method can yield incredibly different results. Randomness can be used to create a sense of chaos and unpredictability when applied in a certain way, but it can also be used to recreate the feel of human presence when employed as a balance against rhythmic quantization.

We’ll start with the [random] object, which is the main random number generator in Max. It has two inlets: on the right, it takes an integer to set the range, and on the left, it takes a bang to output a random number within that range. The range set by the integer has one important caveat: [random] begins counting from 0, not 1! This means that if we set the range to 10, as in the video, the possible numbers are 0 through 9, not 1 through 10. Likewise, by setting the range to 12 (as in the 12 notes of the chromatic scale), we get the numbers 0 through 11, and never 12 (though as we are counting from 0, there are still 12 possible results.)

This is a little counter-intuitive at first, but it’s not actually a limitation. By using what’s called an “offset” we can generate random numbers in any range we like. We establish an offset by using the addition object, [+]. The [+] object adds two numbers together. The number that triggers the calculation goes in the left inlet, which in this case is our random number. It is added to another number that should already be loaded in, either by typing after the “+” (as I have done, preceded by a space), or by sending an integer into the right inlet. (Note that even if you have typed a number into the object itself (like “60”), if you later send a number into the right inlet, the new number will replace 60 in the calculation even though 60 doesn’t disappear.)

In the video, the range of [random] is set to 12 with an offset of [+ 60]. This means that the random numbers will be in the range of (0+60) to (11+60), or 60 to 71. In musical terms, this corresponds to the MIDI note numbers in the octave above middle C (MIDI note number 60). For all of the notes in the first two octaves above middle C, we can simply double the range of [random] to 24 without making any changes to the offset. By plugging this simple combination of objects into the synthesizer we have already built in previous tutorials, we can make a simple random pitch generator. Finally, we can add a [metro] to generate random numbers automatically instead of manually clicking on the button each time.

As an aside, you may have noticed that as the patches get more complicated, I have started paying more attention to the layout of the objects on screen. In general, it is good practice to design patches that are easy to read, and that depict the flow of information as clearly as possible. Take these three principles into consideration as you move forward:

1. Straighten patch cables by clicking on them and pressing command+Y. You can continue to drag cables around after straightening them, but straight lines are generally visually easier to follow than curved ones. In general, short cables are easier to follow than long cables (though sometimes long cables are unavoidable).

2. Connect objects in sequence from top to bottom. When patching, think about how information flows: it’s usually from the outlets (on the bottom) of one object to the inlets (on the top) of another object. This means that for the cleanest layout, objects that receive information should be placed below the objects sending information. If we reflect on the patch in the video, we can see a clear cause-and-effect relationship from top to bottom: (1) the toggle turns on the metronome, (2) the metronome outputs a bang, (3) the bang generates a random number, (4) the random number has an offset applied, (5) the random number triggers an envelope and changes the frequency of the oscillator, (6) the oscillator and envelope are multiplied together, and (7) the resulting sound is sent to the speakers.

3. Finally, also consider expanding objects horizontally to make your patch more legibile by shortening cable length. When the patch is unlocked, you can drag the corners of any object to make it wider or narrower. In the patch in the video, because the [function] object is large, I prefer it to be separated off to the right from other elements. By dragging the [t i b] object to be wider, I ensure that the patch cable going to the function object is straight and as short as possible. I expand the [*~] object below in complementary fashion below as well.