commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Sterijevski <gsterijev...@gmail.com>
Subject [math] MersenneTwister question
Date Mon, 29 Aug 2011 05:17:26 GMT
Hello All,

In the MersenneTwister implementation in commons, I notice the following:

    @Override
    public void setSeed(int seed) {
        // we use a long masked by 0xffffffffL as a poor man unsigned int
        long longMT = seed;
        mt[0]= (int) longMT;
        for (mti = 1; mti < N; ++mti) {
            // See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier.
            // initializer from the 2002-01-09 C version by Makoto Matsumoto
            longMT = (1812433253l * (longMT ^ (longMT >> 30)) + mti) &
0xffffffffL;
            mt[mti]= (int) longMT;
        }
    }

While probably not a big deal, shouldn't the initial element in the array mt
be 'anded' by 0xffffffffL?

mt[0]= (int) longMT & 0xffffffffL;

Thanks,

-Greg

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message