[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnubg] I still have a small problem with the dice generator.
From: |
Joern Thyssen |
Subject: |
Re: [Bug-gnubg] I still have a small problem with the dice generator. |
Date: |
Tue, 4 May 2004 08:39:52 +0000 |
User-agent: |
Mutt/1.4.2.1i |
On Mon, May 03, 2004 at 11:22:17PM +0200, Ã?ystein Johansen wrote
> Ãystein Johansen wrote:
> | in genrand_int32() in mt19937ar.c line 123:
> |
> | ~ if (*mti == N+1) /* if init_genrand() has not been called, */
> | ~ init_genrand(5489UL,mt); /* a default initial seed is used */
> |
> | The above condition comes TRUE, and the dice seed is set to 5489.
> | This makes every first game of a match/session exactly the same. Starts
> | with 51, 66, 61, 62 ....
> |
> | The strange thing is that the condition becomes TRUE, because
> | init_genrand() is called earlier in the in the code (even several times).
> |
> | Can someone explain? Can someone with the right knowledge fix?
>
> Looks like Jørn can!
>
> Silly of me not notising that the calls didn't use the right arguments,
> and why didn't the compiler warn?
It was more complicated than that...
The original M-T code had "mti" as a global parameter. The subroutine
init_genrand used mti in a loop (for mti=1; mti < ...), which has the
side effect of setting mti = N.
When I modified the M-T code to take the internal state as a parameter I
didn't notice this, so I just added an local loop variable.
What I did now was to add "mti" as a parameter to init_genrand, so ensure
the "side effects". The same could have been achieved by setting mti = N
after each call to init_genrand.
Jørn