randomWH API
Generation of Pseudo-Random Variates
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
congruent Struct Reference

An instance of the Congruence struct. More...

#include <randomWH.h>

Detailed Description

An instance of the Congruence struct.

The four seeds used by the generator are stored in this struct. Because they must have global scope, they are contained within a structure to minimise the chances of a name conflict with other variables of global scope. The functions to process these values are accessed via function pointers contained within the struct. This simulates the member function concept of C++ using only C code. Most applications will require only a single generator instance - this one has safe values assigned to the member function pointers.

Usage

#include <stdio.h>
#include "randomWH.h"
#define SIM_DURATION 40000000L
.
.
.
double mean=0, moment2=0, unif, variance;
long int count;
congruent.init(&congruent,1L,2L,3L,4L);
for(count =0;count<SIM_DURATION;count++){
unif = congruent.randomWH(&congruent);
mean += unif;
moment2 += (unif*unif);
}
mean /= SIM_DURATION;
moment2 /= (SIM_DURATION-1.0); // using Bessel's correction
variance = moment2-mean*mean*(SIM_DURATION)/(SIM_DURATION-1.0); // Bessel's correction continued
printf("Mean after %ld iterations is %lf; sample variance is %lf\n", SIM_DURATION, mean, variance);
See Also
Congruence
Note
You may create other generators by declaring other structs of type Congruence but you must initialise them correctly.

The documentation for this struct was generated from the following file: