package rice2604hw; /* ================================================= RandomEnvelopeCreator ------------------------------------------------- A static class which returns an array of doubles to be used by Jsyn as an envelope. The numbers are calculated randomly, but time will add up to the received total time 'length'. ================================================= 2604 J.Rice 10/99 =================================================*/ import java.lang.*; //-------------------------------------------------------------------------- public class RandomEnv { public static double[] getEnv(double length) { int i, x = 0; double localT = 0.0; double[] d = new double[30]; //---------------------------------- for (i = 0; localT < length; i++) { d[i * 2] = (Math.random() * (length / 2.0)); //Calc Time localT = localT + d[i * 2]; //Add time to sum for comparison d[i * 2 + 1] = (Math.random()); //Calculate level x = i; //<--Preserve index value to take out of loop } //End loop //---------------------------------- d[x * 2] = d[x * 2] - (localT - length); //trim last value to //conform to total time d[x * 2 + 1] = 0.0; // set last level to zero return d; } }//==========================================================================