Random Numbers
A set of numbers may be random when there are many numbers in a sequence and their values are independent of each other
Random numbers can be uniformly distributed or nonuniformly distributed
Pseudorandom Numbers using a Computer
Linear Congruential Method
Xn+1 = (aXn + c) mod m, n>=0
X0 = random number "seed"
Example: X0 = a = c = 7, m = 10 yields the sequence 7, 6, 9, 0, 7, 6, 9, 0 (not very long before repetitions start)
Seed can be initialized to any integer, including a nondeterministic value such as a timer or white noise source
Uniform Random Numbers in UNIX
rand() - UNIX random number generator
generates uniform random integers between [0, RAND_MAX+1)
To generate a uniform random integer y between [a,b),
x = rand()
y = (b-a)*(x/RAND_MAX+1) + a
Probability Basics
If S is a set of all possible outcomes of an event, and A is a set denoting the ways a particular outcome can be achieved, then the probability of event A is given by Pr(A) = |A|/|S|
Example: What is the probability of rolling a total of 7 with two fair six-sided dice? Answer: Pr(7) = 6/36 = 1/6.
Discrete Distribution Function
Suppose that the possible choices of an event are given by the set C = {x1, x2, ..., xn}
Discrete Distribution Function: f(x) = Pr(X = x)
Properties: 0 <= f(x) <= 1 for all x in C, and SUM(f(x)) = 1 over all C
Example: Let X be the roll of one fair die.
f(1) = Pr(X=1) = 1/6
f(2) = Pr(X=2) = 1/6
f(3) = Pr(X=3) = 1/6
f(4) = Pr(X=4) = 1/6
f(5) = Pr(X=5) = 1/6
f(6) = Pr(X=6) = 1/6
Cumulative Probability Distribution Function
Cumulative Probability Distribution Function F(x) = Pr(X <= x)
Example: Rolling one fair die:
F(1) = Pr(X<=1) = 1/6
F(2) = Pr(X<=2) = 2/6
F(3) = Pr(X<=3) = 3/6
F(4) = Pr(X<=4) = 4/6
F(5) = Pr(X<=5) = 5/6
F(6) = Pr(X<=6) = 6/6
Markov Process (0th Order) - example done in class
List the possible events (pitches or durations) in an array C[].
Fill out the distribution function in an array f[] describing the relative probability for each choice. (The sum of all elements in f should be 1.)
Compute the corresponding cumulative distribution function in an array F[] from the distribution function f[].
Repeat: Choose a random number in [0,1) and find the index i of the first value in the F array that is not less than the random value and return C[i].
1st Order Markov Process - example done in class
Same procedure except arrays are two-dimensional.
Each event is a note-pair
The probability of a 2-note sequence "x followed by y" is stored in f[x][y].
All values stored in a row of the f table should add up to 1.
2nd Order Markov Process - example done in class
Same procedure: arrays are still two dimensional (can be 3D too).
Each event is a note triple.
The probability of a 3-note sequence "x,y followed by z" is stored in f[xy][z] where xy represents some unique row of the array corresponding to the note pair x,y. (You'll need a lookup table to translate note pairs to row indices.)
All values stored in a row of the f table should add up to 1.
More on Markov Processes
Can be used to control any musical event: pitch, duration, etc.
Can be taken to any order of complexity.
The higher the order of the process, the more similar the computer music random composition will sound to the original.
Fractal Music (1/fb Noise)
Use a random number generator to generate pitches for a music composition
Subsequent random numbers are restricted based on the value of previous random numbers
White (1/f0) Noise
Easy to generate random numbers
Each random number is independent of the numbers chosen before
If the random number represents pitch, then any pitch is equally-likely to be the next pitch.
Brownian (1/f2) Noise
Also called a "random walk"
Subsequent random number is a uniform random distance from the previous random number
Generates a noise signal whose spectrum resembles the function 1/f2.
To generate: Start with a pitch. Generate a random number between [-a,a] and add to pitch value to generate new pitch. Repeat on new pitch. (a = maximum pitch variation above or below previous pitch in half steps)
1/f Noise
Sum the output of N uniform random number generators labeled [0..N-1], where generator i generates a new random number after every 2i uses. Sum the output of these generators to get a musical quantity like pitch.
Generates a noise signal whose frequency spectrum resembles the function 1/f.
Generating 1/fb Noise
Generate a uniformly distributed sequence of random numbers (white noise) representing some musical quantity like pitch
Take the DFT or FFT to get the frequency spectrum
Shape (multiply, filter) the spectrum by 1/fb for some chosen b
Take the IDFT or IFFT to get the new sequence of random numbers
COURSE INFORMATION | HOMEWORK ASSIGNMENTS
COURSE PROJECT | CS240 HELP DESK