Random Number - page 2

 
Dominik Christian Egert #: Yes, I agree to point 1. And see that issue as well, which I haven't taken into consideration.

But I disagree about modulo operator. Short, theoretical example: random numbers between 1 and 10, modulo by 8. You will see more of 1s and 2s. Your range must be a multiple of the modulo operator. Which is not possible with 32767 being the biggest number in the range. I need a computer to verify this.... Ha. But, MathRand() % 5 will not uniformly distribute.

That is NOT how William is using the modulus function in the example in his link. He is using modulus for the range max calculation, not against the random number generator itself.

EDIT: Correction ... Actually he is using the modulus function against the generator, but only after the filter (aka the while loop).

 
Dominik Christian Egert #: But I "disagree" to modulo operation, 

Fernando Carreiro #: Assuming a uniformly distributed random number generator, then the modulus alternative will also be uniformly distributed.

If you had looked at the link provided, the code handles the fact that 32767 is not a multiple of 1000 and gives a uniformly distributed result using modulo.

 
I missed that link...but I remember reading exactly that thread a while ago.


Reason: