Question

I'm trying to generate discrete random numbers with uniform distribution using Intel MKL. The function viRngUniformBits32 generates n random integers. I want to generate random numbers on the fly rather than generating them n at a time. I tried this but obviously it doesn't work. I call the function 5 times and it outputs the same value. I assume it is generating the first number in the sequence every time based on the seed value. Now how do I modify this so that every time I call this method, I get a random number

#include <stdio.h>
#include "mkl.h"
int main()
{
    unsigned int out;
    VSLStreamStatePtr stream;
    vslNewStream(&stream,VSL_BRNG_MCG31,2);
    for (int i=0;i<5;i++)
    {
        //FORMAT viRngUniformBits32( method, stream, n, r );
        viRngUniformBits32(VSL_RNG_METHOD_UNIFORMBITS32_STD,stream,1,&out);
        printf("%u\t",out);
    }
        printf("\n");
    vslDeleteStream(&stream);
}
Was it helpful?

Solution

The method viRngUniformBits32 does not support the BRNG VSL_BRNG_MCG31.

So I used VSL_BRNG_MT19937 and it works without any errors.

Thanks to jaket for reminding me to look at the error code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top