# random

## Motivic "improviser"

This patch enacts a particular type of improvisational behavior, playing a partial statement of a stored motivic phrase. The phrase is stored in a coll (collection) object, as an ordered array of lists, with each list containing three numbers: pitch, velocity, and duration for a MIDI note message. Each time a message comes in the inlet, the patch chooses a transposition of the motive at random, chooses a number of notes to play, and starts a metro to begin counting through the numbered items in the coll.

## Random semitone trills

A trill can be thought of as a fast back-and-forth alternation between two pitches—or more generally as fast back-and-forth alternation between any two things or states. A back-and-forth or on-off switch can be implemented in any programming language by setting a boolean variable (a variable that's capable of having only one of two states) to its opposite state, with an expression in the form of "If it's 'X', set it to 'NOT X', otherwise, set it to 'X'."

## Random voicings of a pitch class set

A chord can be described as a pitch class set. For example, a C dominant ninth chord is the pitch class set {0,2,4,7,10}. Depending on the octave transposition of each of those five pitch classes, many voicings of the chord are possible. This patch take applies a transposition of four, five, six, or seven octaves to each of the five pitch classes to create a random voicing of the chord.

## Sequential or random access of a lookup table

One of the nice features of an array is that you can store data in a particular order, then recall it in that order simply by incrementing an index counter. Or you can access the data randomly, which still restricts your outcome to members of that data set but ignores the original order.

## Pseudo-random numbers appear random

Programming languages all provide some means of generating random numbers. Those numbers aren’t truly random, though. They’re what’s called pseudo-random. They’re actually generated by a known, deterministic process for generating a sequence of numbers, but that process generates a long series of apparently random numbers that doesn’t repeat for a very long time.

## MIDI and audio via ReWire

Max can interface with other applications via ReWire. Max can act as either a ReWire host or a ReWire client. Max can be a client to an open host application just by choosing "ad_rewire" as the MSP audio driver in the DSP Status window. Alternatively, you can use Max as the host (mixer) application by including the rewire~ object in your program.

## Rhythmic delays in time with a musical tempo

The tempo-relative timing capabilities in Max can be used to synchronize MSP processing in time with a musical beat. In this example, timings of delays are specified in tempo-relative time units so that they remain rhythmically correct for any tempo.

## Random note choices

The left part of this example shows the use of the random object to make arbitrary note choices. Every time random receives a bang in its inlet, it sends out a randomly chosen number from 0 to one less than its argument. In this case it chooses one of 61 possible key numbers, sending out a number from 0 to 60. We then use a + object to offset that value by 36 semitones, transposing up three octaves to the range 36 to 96––cello low C to flute high C.