views:

39

answers:

1

Hi everyone, 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.

Thanks everyone

A: 

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.

Potatoswatter