4 ms·
> the multiplicative method ensures that all the integer values possible for the result have the same probabilities Uh, you can't do that for any non-power-of-
by lifthrasiir 5y ago
> the multiplicative method ensures that all the integer values possible for the result have the same probabilities
Uh, you can't do that for any non-power-of-two K. The multiplicative method doesn't remove but only moves those lower probabilities around when used without rejection.
- adrian_b 5y agoYou are right in general, but for the common case, when you want random numbers with the maximum value much less than the maximum integer that can be represented in a word, e.g. you want dice numbers or lottery numbers, the probabilities of the integers produced by multiplication are much more uniform than of those produced by modulo. If you would want a very wide range for the output random numbers, which is seldom the case, the comparison of the methods could be reversed.
- atq2119 5y agoNo. The two methods are qualitatively equally good. In both cases, some outputs have probability floor(2^n/K)/2^n while others have probability ceil(2^n/K)/2^n. The numbers of outputs with each probability are such that they average out to 1/K. The only difference is the distribution of which output numbers have which of these two probabilities.
- pwuille 5y agoExactly, both the modulo and the multiplicative method are equally close to uniform. In fact, under the constraint of starting from a uniform input with 2^n possibilities, both produce an output that is as close to uniform as possible. A necessary and sufficient requirement for that is the maximum and minimum number of inputs that maps to any given output differs by at most one, which is the case for both methods.