Orand
INSTRUMENT design -- pseudo-random number generator object
The Orand object can be used to generate streams of
pseudo-random numbers. The generating algorthm can be seeded
by a particular seed value or can be set by the system clock,
thus creating a different sequence of random numbers for every
run of the algorithm.
It brings together and can be used to replace a number of
older pseudo-random number functions scattered throughout
cmix/RTcmix, including the
rrand,
srand, and
random
functions.
The pseudo-random number generator used in the RTcmix distribution
isn't the latest and greatest, but it seems to do the job well
enough for us flaky musicians.
Constructors
Orand()
-
creates a new pseudo-random number generator with a default seed value
of 1.
Orand(int seed)
-
seed is the seed value for the pseudo-random number generator
created.
Access Methods
float Orand::timeseed()
-
will seed the pseudo-random number generator
using the system clock to generate the seed value.
float Orand::random()
-
returns a floating-point pseudo-random number between 0.0 and 1.0.
The sequence of random values depends on the setting of the seed value.
float Orand::rand()
-
returns a floating-point pseudo-random number between -1.0 and 1.0.
The sequence of random values depends on the setting of the seed value.
float Orand::range(float lo, float hi)
-
returns a floating-point pseudo-random number between
lo and hi.
The sequence of random values depends on the setting of the seed value.
Examples
#include <Ougens.h>
Orand *theNoise;
// this instrument will generate noise
int MYINSTRUMENT::init(float p[], int n_args)
{
...
theNoise = new Orand();
theNoise->timeseed();
...
}
int MYINSTRUMENT::run()
{
float out[2];
...
for (i = 0; i < chunksamps; i++)
{
out[0] = theNoise->rand();
}
...
}