Raymond Toy wrote:
(snip, I wrote)
> glen> This is true if m is a power of two. I believe it isn't
necessarily
> glen> true if m is not a power of two. It is very common, though,
for m
> glen> to be a power of two. Otherwise, if I need random low bits I
divide
> glen> by a prime number sort of near sqrt(m) before using it.
> Do you take the remainder as the random number? If so, this has a
> bias, so the result isn't quite uniform. May or may not matter.
Divide by some fairly large prime, then mod the (small) number
of choices I would like. For a simulated dice roll, modulo 6.
It won't be perfectly uniform, but close enough for most uses.
It should be much better than some of the microsoft card games,
which sometime don't seem very random at all.
-- glen


|