开发者

Upper bound for custom rand48

开发者 https://www.devze.com 2022-12-25 18:17 出处:网络
I\'m using a custom random number function rand48 in CUDA. The function does not allow an upperbound to be set, but I require the output to be between 0 and 1.

I'm using a custom random number function rand48 in CUDA. The function does not allow an upperbound to be set, but I require the output to be between 0 and 1.

I guess I'm missing something but how would I convert the output to be between 0 and 1, the length of the number can change e.g. 697135872 would need to be divided by 100000000 and 29186668 would need to be divided by 100000000.

Thank开发者_如何学编程s everyone


If your PRNG behaves like rand then it generates numbers between 0 and RAND_MAX with uniform probability. You just have to multiply by 1.f/RAND_MAX.

If you divide by different numbers in different cases, you will end up with non-uniform distribution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号