- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatChapter9/C091204a.cpp File Reference

`#include "MusimatChapter9.h"`

Go to the source code of this file.

## Functions
| MusimatChapter9Section (C091204a)
IntegerList | randomRow (Integer N)
Static Void | para1 ()

## Function Documentation

MusimatChapter9Section | ( | C091204a |  | ) |

Definition at line 2 of file C091204a.cpp.

References para1().

    00002                                  {
    00003 Print("*** Sampling without Replacement ***");
    00004 /*****************************************************************************
    00005
    00006 Sampling without Replacement
    00007
    00008 We can generate a randomly selected 12-tone row, for example,
    00009 by putting 12 balls in an urn, each marked with one of the chromatic pitch classes, and draw them out
    00010 one at a time without replacement, thereby guaranteeing that no pitch class is chosen more than once.
    00011
    00012 Random(0, 11) returns a random integer between 0 and 11 with equal probability. But it could
    00013 return the same value multiple times, so we must keep track of which pitch classes have been cho-
    00014 sen to ensure that it eventually picks one of each. This function takes one argument, N, determining
    00015 the length of the row.
    00016 *****************************************************************************/
    00017         para1(); // Step into this function to continue.
    00018 }

Static Void para1 | ( |  | ) |

Definition at line 41 of file C091204a.cpp.

References randomRow().

    00041                     {
    00042 /*****************************************************************************
    00043 Note that the second loop keeps repeating over and over until Random() has finally selected
    00044 all N pitch classes. It then returns the newly created 12-tone row in M.
    00045 *****************************************************************************/
    00046         Print("*** Random Row ***");
    00047         Print("A random row:", randomRow(12));
    00048
    00049 /*****************************************************************************
    00050 Here is an example row created by randomRow():
    00051
    00052 {0, 6, 2, 9, 7, 5, 4, 10, 8, 3, 1, 11};
    00053
    00054 Every pitch class is represented exactly once.
    00055 *****************************************************************************/
    00056 }}

IntegerList randomRow | ( | Integer | N | ) |

Definition at line 20 of file C091204a.cpp.

References Random(), and x.

    00020                                  {
    00021         IntegerList L;                                          // keep track of pitches chosen so far
    00022         IntegerList M;                                          // used to build up random 12-tone row
    00023         Integer i;
    00024
    00025         // set all list elements to zero, which means "unused"
    00026         For (i = 0; i < N; i = i + 1) {L[i] = 0;}
    00027
    00028         // build up M, marking off elements in L when they are chosen
    00029         i = 0;
    00030         While (i < N) {
    00031                 Integer x = Random(0, N - 1);           // returns integer random value
    00032                 If (L[x] == 0) {                                        // hasn’t been chosen yet?
    00033                          L[x] = 1;                                              // mark it "used"
    00034                          M[i] = x;                                              // save result
    00035                          i = i + 1;                                     // increment control variable
    00036                 }
    00037         }
    00038         Return(M);
    00039 }