#include "MusimatChapter9.h"Go to the source code of this file.
Functions | |
| MusimatChapter9Section (C091204a) | |
| IntegerList | randomRow (Integer N) | 
| Static Void | para1 () | 
| MusimatChapter9Section | ( | C091204a | ) | 
Definition at line 2 of file C091204a.cpp.
References para1().
                                 {
        Print("*** Sampling without Replacement ***");
        /*****************************************************************************
         
         Sampling without Replacement
         
         We can generate a randomly selected 12-tone row, for example, 
         by putting 12 balls in an urn, each marked with one of the chromatic pitch classes, and draw them out 
         one at a time without replacement, thereby guaranteeing that no pitch class is chosen more than once.
         
         Random(0, 11) returns a random integer between 0 and 11 with equal probability. But it could 
         return the same value multiple times, so we must keep track of which pitch classes have been cho-
         sen to ensure that it eventually picks one of each. This function takes one argument, N, determining 
         the length of the row.
         *****************************************************************************/
        para1(); // Step into this function to continue.
}
| Static Void para1 | ( | ) | 
Definition at line 43 of file C091204a.cpp.
References randomRow().
                    {
        /*****************************************************************************
         Note that the second loop keeps repeating over and over until Random() has finally selected 
         all N pitch classes. It then returns the newly created 12-tone row in M. 
         *****************************************************************************/
        Print("*** Random Row ***"); 
        Print("A random row:", randomRow(12));
        
        /*****************************************************************************
         Here is an example row created by randomRow(): 
         
         {0, 6, 2, 9, 7, 5, 4, 10, 8, 3, 1, 11}; 
         
         Every pitch class is represented exactly once.
         *****************************************************************************/
}
| IntegerList randomRow | ( | Integer | N ) | 
Definition at line 20 of file C091204a.cpp.
                                 {
        IntegerList L;                                          // keep track of pitches chosen so far
        IntegerList M;                                          // used to build up random 12-tone row
        Integer i;
        
        // set all list elements to zero, which means "unused"
        For (i = 0; i < N; i = i + 1) {
                L[i] = 0;
        }
        
        // build up M, marking off elements in L when they are chosen
        i = 0;
        While (i < N) {
                Integer x = Random(0, N - 1);           // returns integer random value
                If (L[x] == 0) {                                        // hasn't been chosen yet?
                        L[x] = 1;                                               // mark it "used"
                        M[i] = x;                                               // save result
                        i = i + 1;                                      // increment control variable
                }
        }
        Return(M);
}
 1.7.2