/Users/lyon/j4p/src/sound/StochasticControl.java

1    package sound; 
2     
3    /* 
4     * Open Source Software by http://www.Docjava.com 
5     * programmer: D. Lyon 
6     * e-mail: lyon@docjava.com 
7     * Date: Apr 29, 2002 
8     * Time: 12:57:33 PM 
9     */ 
10    
11   public class StochasticControl { 
12       public static void testRandomNotes() { 
13           randomNotes(12, 70, 100, 250); 
14       } 
15    
16       /** 
17    
18        * play randomNotes from a scale 
19    
20        */ 
21       public static void randomNotes( 
22               int scale[], int numberOfNotes) { 
23           for (int i = 0; i < numberOfNotes; i++) { 
24               int r = getRandom(0, scale.length); 
25               Utils.play(scale[r], 50 * getRandom(1, 4)); 
26           } 
27       } 
28    
29       public static void randomNotes(int noteMin, int noteMax, 
30                                      int numberOfNotes, 
31                                      int duration) { 
32           for (int i = 0; i < numberOfNotes; i++) 
33               Utils.play(getRandom(noteMin, noteMax), duration); 
34       } 
35    
36       private static void testRandom() { 
37           for (int i = 0; i < 10; i++) 
38               System.out.println(getRandom(1, 12)); 
39       } 
40    
41       public static int getRandom(int min, int max) { 
42           return (int) ((max - min) * Math.random() + min); 
43       } 
44   } 
45