You are on page 1of 1

Interlude A - Prog ramm ing wit h Max/MSP IA

If you also add a number box to t he right inlet of the addition operato r, you w ill
be able to modify both th e range and the base number from w hich it departs
(as shown in f igure IA.14 ).

.L
random 11
QD
t}~
dO
@
Fig . IA. 14 Random numbers w it h a variable range

In th e example shown in f igure IA.14, we see t hat t he new arguments sent fr om


the number boxes are 30 fo r random (resulting in random numbers betwee n 0
and 29) and 100 for the addit ion object. The results wi ll be therefore numb ers
betwee n 100 and 129.
So far, w e have generated random numb ers spanning various intervals (0-99,
50-60, 50-79, and 100-129) by choosing th e correct arguments for ran do m
and for th e addition object in o ur patch. Is there a simple rule that w ill always
enable us to generate a random series from just a minimum and a maximum
number? Obviously the answer is yes: given a minim um num ber 'x' and
a maximum number 'y', we can f irst calculate t he range, or the distance,
betwee n x and y, and t his number, plus 1, w ill become t he argument to
random. The min imum value, x, must the n be added to the number generated
by random; the mi nimum numbe r, x, w ill be t he argument to th e addit ion
operator . For example, if you wanted to generate numbers between 1000 and
1100, you wo uld calculate the diff erence betwe en 1000 and 1100, giving you
100. Add ing 1 to this yields 101, wh ich w ould be the argument to rand om,
w hile the argum ent for the + object w ou ld be t he minimum number itself,
1000. Test this by typin g th e numbe rs 101 and 1000 into the two number
boxes in t he patch IA.14.
The rule for extracting a range fro m two arguments is simple and effective, but
it can be inconvenient to calculate by hand: w hy not do it using Max? The inter-
val between two numbers is not hing more than t he diffe rence between two
numbers, which can be quickly calculated w it h the - object , as in figur e IA.15 :
maximum minimum

t►~ :)t 1000 J

1J,oo1
difference

Fig . IA.15 Calculating t he diffe rence between two numbers

To obtain th e range between tw o numbers, we must subtract th e min imum


number from t he maximum number. This interval must then be augmented by
1 befo re using it as an argument to random, since t he object generates random
139

You might also like