Hello!

On Mon, Jul 18, 2005 at 11:02:54AM -0700, Jack Bates wrote:
>[...]

>4) Do not use the % (modulo) operator to select a card.  The residues from
>% introduce small amounts of bias, and this is a disqualifying factor for
>regulated gaming.

Does that point still hold, assuming I use a modulus which is a divisor
of the range of the original random values?

I use the following algorithm, assuming a random generator that
yields k-bit unsigned numbers of randomness, to yield random numbers
between 0 and n-1:

- determine the maximum multiple of n which is <= 2^k, call that m
- get a random number from the source generator, until that number
  is < m, call that r
- return (r % n)

By re-getting random numbers, I transform the source (P)RNG into
a (P)RNG that yields numbers >= 0, < m, and m is a multiple of n,
that should eliminate the bias, as long as the (P)RNG doesn't
have a bias if the previous number it yielded was >= m.

>[...]

Kind regards,

Hannah.

Reply via email to