Generating random numbers with uniform distribution using Thrust

前端 未结 4 639
礼貌的吻别
礼貌的吻别 2020-12-09 22:41

I need to generate a vector with random numbers between 0.0 and 1.0 using Thrust. The only documented example I could find produces ve

4条回答
  •  既然无缘
    2020-12-09 23:20

    It might not be a direct answer to your question but, cuRand library is quite powerful in this concept. You may both generate random numbers at GPU and CPU, and it contains many distribution functions (normal distribution etc).

    Search for the title: "An NVIDIA CURAND implementation" on this link: http://adnanboz.wordpress.com/tag/nvidia-curand/

    //Create a new generator
    curandCreateGenerator(&m_prng, CURAND_RNG_PSEUDO_DEFAULT);
    //Set the generator options
    curandSetPseudoRandomGeneratorSeed(m_prng, (unsigned long) mainSeed);
    //Generate random numbers
    curandGenerateUniform(m_prng, d_randomData, dataCount);
    

    One note is that, do not generate the generator again and again, it makes some precalculations. Calling curandGenerateUniform is quite fast and produces values between 0.0 and 1.0.

提交回复
热议问题