Tscope5
randomizer.c File Reference

Definitions of randomizer functions. More...

Go to the source code of this file.

Functions

Random integers

In an experiment most of the time you will need random integers, preferably drawn from a list without replacement:

unsigned long int ts5_random_integer (const unsigned long int max)
 Draw an integer from a uniform distribution. More...
 
void ts5_random_list (const int nmax, const int freq, int *list)
 Draw a list of random values without replacement. More...
 
Random doubles

Tscope5 also gives acces to random numbers drawn from some common distributions:

double ts5_random_uniform ()
 Draw a double from a uniform distribution. More...
 
double ts5_random_normal (double mu, double sigma)
 Draw a double from a normal distribution. More...
 
double ts5_random_exponential (double mu)
 Draw a double from an exponential distribution. More...
 
Set the random seed

If you do simulation work it is also possible to set the random seed yourself.

Identical seeds always result in the same randomized list.

unsigned long int ts5_seed_randomizer (const unsigned long int seed)
 Seed the randomizer subsystem. More...
 

Detailed Description

Definitions of randomizer functions.

Definition in file randomizer.c.

Function Documentation

unsigned long int ts5_random_integer ( const unsigned long int  max)

Draw an integer from a uniform distribution.

Parameters
maxNumber of possible values of the random integer.
Returns
An integer from 0 to n-1.
Examples:
randomizer01.c, randomizer03.c, timer03.c, timer04.c, timer05.c, and timer06.c.

Definition at line 42 of file randomizer.c.

void ts5_random_list ( const int  nmax,
const int  freq,
int *  list 
)

Draw a list of random values without replacement.

Parameters
nmaxMaximum value (output values will range from 0 to n-1).
freqFrequency of each value.
listAdress of the array where the list is stored.
Examples:
randomizer01.c.

Definition at line 58 of file randomizer.c.

double ts5_random_uniform ( )

Draw a double from a uniform distribution.

Returns
A double precision floating point value from a uniform distribution.

The range includes 0.0 but excludes 1.0.

Examples:
randomizer02.c.

Definition at line 92 of file randomizer.c.

double ts5_random_normal ( double  mu,
double  sigma 
)

Draw a double from a normal distribution.

Parameters
muMean of the distribution.
sigmaStandard deviation of the distribution.
Returns
The random value.
Examples:
randomizer02.c.

Definition at line 109 of file randomizer.c.

double ts5_random_exponential ( double  mu)

Draw a double from an exponential distribution.

Parameters
muMean of the distribution.
Returns
The random value.
Examples:
randomizer02.c.

Definition at line 125 of file randomizer.c.

unsigned long int ts5_seed_randomizer ( const unsigned long int  seed)

Seed the randomizer subsystem.

Parameters
seedSeed for the randomizer.

If the generator is seeded with the same value of seed on two different runs, the same stream of random numbers will be generated by successive calls to the routines.

The timer is a good source for random seeds.

Examples:
randomizer03.c.

Definition at line 154 of file randomizer.c.