Generating random number within Cuda kernel in a varying range

前端 未结 2 1519
天涯浪人
天涯浪人 2020-12-16 07:59

I am trying to generate random number random numbers within the cuda kernel. I wish to generate the random numbers from uniform distribution and in the integer form, startin

2条回答
  •  Happy的楠姐
    2020-12-16 08:39

    @Robert's example doesn't generate a perfectly uniform distribution (although all the numbers in the range are generated and all the generated numbers are in the range). Both the smallest and largest value have 0.5 the probability of being chosen of the rest of the numbers in the range.

    At step 2, you should multiply with the number of values in the range: (largest value - smallest value + 0.999999). *

    At step 3, the offset should be (+ smallest value) instead of (+ smallest value + 0.5).

    Steps 1 and 4 remain the same.

    *As @Kamil Czerski noted, 1.0 is included in the distribution. Adding 1.0 instead of 0.99999 would sometimes result in a number outside of the desired range.

提交回复
热议问题