[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnubg] The dice are (slightly) rigged

From: Philippe Michel
Subject: [Bug-gnubg] The dice are (slightly) rigged
Date: Tue, 22 Nov 2011 23:11:49 +0100 (CET)
User-agent: Alpine 2.00 (BSF 1167 2008-08-23)

Currently, dice generation code for the Mersenne twister random number generator looks like this :

dice = 1 + (int)(6.0 * genrand_int32(&rngctx->mti, rngctx->mt) / (0xFFFFFFFF + 1.0));

that is, the rng provides a random integer between 0 and 2^32-1 and it is mapped to a value between 1 and 6.

The trouble is that, since 2^32 is not a multiple of 6, a bias is introduced and we get 715827883 aces, deuces, fours and fives for 715827882 threes and sixes...

Some of the other rngs implemented in gnubg have a similar problem.

It is certainly unnoticeable in practice from the rolls stream, but it wouldn't hurt to avoid this.

Are there list members who are knowledgeable on rng robustness and could confirm that, if one starts with a "good" rng for integers uniformly distributed between 0 and n and discards any occurence of the top p values, one gets a good rng for the [0, n-p] interval ?

Intuitively, it is tempting to say : "yes, and it is a condition for the original generator being any good" but I'm afraid it may be a treacherous domain.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]