Complete code for Example 2: non-uniform variate generation
#include <clRNG/mrg31k3p.h>
cl_double simulateOneRun(cl_double lambda, clrngMrg31k3pStream* stream)
{
cl_double output = 0.0;
for (int i = 0; i < 100; i++) {
cl_double u = clrngMrg31k3pRandomU01(stream);
}
return output;
}
int main()
{
int replications = 1024;
cl_double lambda = 50.0;
clrngMrg31k3pStream* stream = clrngMrg31k3pCreateStreams(NULL, 1, NULL, NULL);
cl_double sum = 0.0;
for (int i = 0; i < replications; i++)
sum += simulateOneRun(lambda, stream);
printf("The average output is %.3f\n", sum / replications);
clrngMrg31k3pDestroyStreams(stream);
return 0;
}