Function for Creating a Random Number Stream
Initialize the stream structure and set the random number seed.
Interface Definition
int vslNewStream(VSLStreamStatePtr *stream, const int brng, const unsigned seed);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
stream |
Pointer of the VSLStreamStatePtr type |
Pointer to the random number stream structure. |
Output |
brng |
int |
Random number generator type.
|
Input |
seed |
unsigned |
Random number seed, which must be a non-negative integer. |
Input |
Dependencies
#include "krng.h"
Examples
#include <stdio.h>
#include <stdlib.h>
#include "krng.h"
int main()
{
/* initialize stream with given BRNG type and seed */
VSLStreamStatePtr stream;
unsigned seed = 42;
int errcode = vslNewStream(&stream, VSL_BRNG_MCG59, seed);
if (errcode != VSL_STATUS_OK) {
fprintf(stderr, "Failure in newstream\n");
return 0;
}
/* deinitialize the stream */
errcode = vslDeleteStream(&stream);
if (errcode != VSL_STATUS_OK) {
fprintf(stderr, "Failure in deleting stream\n");
return 0;
}
return 0;
}
Parent topic: High-performance Functions