## JMSL Tutorial: MusicShape

One of the great joys of hacking JMSL is developing algorithms
that generate interesting MusicShapes. So let's spend a little
time doing just that.

We will build a MusicShape which displays an increasing
random variation from a central value. So the algorithm to generate
element[i] will depend partially on the index i itself (ie the value is a
function of the index).

The key to this algorithm is the ChoosePlusMinus(int arg) method in
the JMSLRandom class. This method chooses a random int between +arg and -arg
(there is also a version for double). A fragment illustrates:

for (int i=0; i < numberOfElements; i++){
double value = centralValue + JMSLRandom.choosePlusMinus(i);
myShape.add(value);
}

You see that for example, the 50th value generated will be the result of adding centralValue
to a random number between -50 and 50.

View the source of this applet here.

(C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved
JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.