Abstract Basic Random Number Generators. Abstract Streams
 Random numbers are read from a file into a buffer.
 Random numbers are taken from a physical device that stores numbers into a buffer.
 You study the system behavior under different distribution generator parameters using the same BRNG sequence for each parameter set.
 Your algorithm is sequential but you still want to use a vector random number generator.
For i from 1 to n, do: /* Search for "good" candidate (u,v) */ do u := Uniform() // get successive uniform random number from BRNG v := Uniform() // get successive uniform random number from BRNG until f(u,v)>a /* Get successive nonuniform random number */ w := Nonuniform() // get successive uniform random number from BRNG // and transform it to nonuniform random number /* Return ith result */ r[i] := g(u,v,w) end do
 Generate vectorUof pairs(u, v)
 Applying "good candidate" criterionf(u,v)>a, form a new vectorVthat consists of "good" candidates only.
 Get vectorWof nonuniform random numbersw.
 Get vectorRof resultsg(u,v,w).
Types of Abstract Basic Random Number Generators
 integervalued buffers
 single precision floatingpoint buffers
 double precision floatingpoint buffers
vsliNewAbstractStream( &stream, n, ibuf, icallback);
vslsNewAbstractStream( &stream, n, sbuf, a, b, scallback);
vsldNewAbstractStream( &stream, n, dbuf, a, b, dcallback);
int MyUpdateFunc( VSLStreamStatePtr stream, int* n,<type>buf, int* nmin, int* nmax, int* idx ) { ... /* Update buf[] starting from index idx */ ... return nupdated; }
typedef int (*iUpdateFuncPtr)( VSLStreamStatePtr stream, int* n, unsigned int ibuf[], int* nmin, int* nmax, int* idx ); typedef int (*dUpdateFuncPtr)( VSLStreamStatePtr stream, int* n, double dbuf[], int* nmin, int* nmax, int* idx ); typedef int (*sUpdateFuncPtr)( VSLStreamStatePtr stream, int* n, float sbuf[], int* nmin, int* nmax, int* idx );
Type of Discrete Distribution

Type of Abstract Stream


Uniform

Double precision

UniformBits

Integer

Bernoulli

Single precision

Geometric

Single precision

Binomial

Double precision

Hypergeometric

Double precision

Poisson (VSL_METHOD_IPOISSON_POISNORM)

Single precision

Poisson (VSL_METHOD_IPOISSON_PTPE)

Single and double precision

PoissonV

Single precision

NegBinomial

Double precision

#include <stdio.h> #include "mkl_vsl.h" #define METHOD VSL_METHOD_IPOISSON_PTPE #define N 4500 #define DBUFN 1000 #define M 0x7FFFFFFF /* 2^311 */ static FILE* fp; int MydUpdateFunc(VSLStreamStatePtr stream, int* n, double dbuf[], int* nmin, int* nmax, int* idx) { int i; unsigned int num; double c; c = 1.0 / (double)M; for ( i = 0; i < *nmax; i++ ) { if ( fscanf(fp, "%u", &num) == EOF ) break; dbuf[(*idx+i) % (*n)] = num; } return i; } int main() { int errcode; double lambda, a, b; double dBuffer[DBUFN]; int r[N]; VSLStreamStatePtr stream; /* Boundaries of the distribution interval */ a = 0.0; b = 1.0; /* Parameter of the Poisson distribution */ lambda = 3.0; fp = fopen("ran_nums.txt", "r"); /***** Initialize stream *****/ vsldNewAbstractStream( &stream, DBUFN, dBuffer, a, b, MydUpdateFunc ); /***** Call RNG *****/ errcode = viRngPoisson(VSL_RNG_METHOD_POISSON_PTPE,stream,N,r,lambda); if (errcode == VSL_ERROR_OK) { /* Process vector of the Poisson distributed random numbers */ ... } else { /* Process error */ ... } ... vslDeleteStream( &stream ); fclose(fp); return 0; }