Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Random Number Generator

Ahmadi__Afshin
2,150 次查看

Hello,

 

I am trying to generate a vector of random numbers using the following code. However, every time I execute the code, the output vector is the same as previous run! Can you please help? Thank you in advance. - Afshin

 

    int N = 30;
    double r;
    VSLStreamStatePtr stream;
    int errcode;
    double a=0,sigma=0.5;
   
    /***** Initialize *****/
    errcode = vslNewStream( &stream, VSL_BRNG_MT2203, 10000 );
    printf("err = %i\n",errcode);
    /***** Call RNG *****/
    errcode = vdRngGaussian( VSL_RNG_METHOD_GAUSSIAN_BOXMULLER, stream, N, r, a, sigma );
    printf("err = %i\n",errcode);
    vslDeleteStream(&stream);
 
    for (i=0; i<N; i++){
        printf("r = %f\n",r);
    }

 

0 项奖励
1 解答
Khang_N_Intel
员工
2,150 次查看

Hi Afshin,

This result is expected to be the same from run to run.

If you want the result to be different every time, you will need to change the seed value for each run.  You can use the time function to do that.

Hope this helps!

Best Regards,

Khang

在原帖中查看解决方案

0 项奖励
3 回复数
Khang_N_Intel
员工
2,151 次查看

Hi Afshin,

This result is expected to be the same from run to run.

If you want the result to be different every time, you will need to change the seed value for each run.  You can use the time function to do that.

Hope this helps!

Best Regards,

Khang

0 项奖励
Ahmadi__Afshin
2,150 次查看

Thank you, Khang! You always provide best answers.

0 项奖励
Khang_N_Intel
员工
2,150 次查看

Hi Afshin,

We are here to help users make the best out of Intel(r) MKL.

Please do not hesitate to contact us should you have any questions about Intel(R) MKL.

 

Best Regards,

Khang

0 项奖励
回复