Random number generators discussion

Random number generators | www.agner.org

 
thread Mersenne Twister - Fang Chen - 2004-05-18
last replythread Mersenne Twister - Agner - 2004-05-19
last replythread Mersenne Twister - Fang Chen - 2004-05-19
last reply Mersenne Twister - Agner - 2004-05-20
 
Mersenne Twister
Author:  Date: 2004-05-18 15:51
Hi all:

I have been studying the original MT code, mt19937.c and the improved version, mt19937ar.c. My understanding is that the difference is in using two initialization routines, sgenrand() vs init_genrand(). The sgenrand() function can produce output sequences that are highly correlated if two initial states are not chosen correctly, while the new function doesn't have that problem. Is this a correct understanding? I am also trying to find two initial states (or maybe two initial seeds?) that will produce highly non-random sequences of numbers using the sgenrand() function in mt19937.c to demonstrate this phenomena. Does anyone know if there is a good way to find such two seeds?

Thank you very much and any help will be greatly appreciated.

FC

void
sgenrand(seed)
unsigned long seed;
{
/* setting initial seeds to mt[N] using */
/* the generator Line 25 of Table 1 in */
/* [KNUTH 1981, The Art of Computer Programming */
/* Vol. 2 (2nd Ed.), pp102] */
mt[0]= seed & 0xffffffff;
for (mti=1; mti<N; mti++)
mt[mti] = (69069 * mt[mti-1]) & 0xffffffff;
}


void init_genrand(unsigned long s)
{
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
}

   
Mersenne Twister
Author: Agner Date: 2004-05-19 11:14
The old initialization code might generate somewhat similar sequences if two seeds differ only by the most significant bit. I changed the code after advise from Dr. Matsumoto. See details on his homepage www.math.sci.hiroshima-u.ac.jp/~m-mat/eindex.html
   
Mersenne Twister
Author:  Date: 2004-05-19 12:11
Thank Agner.

My confusion is I am not sure what a "most significant bit" means when it comes to two seeds, does it mean that two numbers differ in their binary representation in only one bit? Like 00 and 01 differ by one bit? So should I expect that two similar sequences if I use sgenrand(0) and sgenrand(1)? (But this doesn't happen I think). On the MT homepage, it says that the most significant bit is not well reflected to the state vector, and that confuses me too.

Any help would be greatly appreciated.

Thanks,

FC

   
Mersenne Twister
Author: Agner Date: 2004-05-20 07:54
You can learn about number systems from elementary textbooks in math or digital electronics.

Fang Chen wrote:

My confusion is I am not sure what a "most significant bit" means when it comes to two seeds, does it mean that two numbers differ in their binary representation in only one bit? Like 00 and 01 differ by one bit?
No. The rightmost bit is the least significant bit. The most significant bit is the leftmost in the binary representation:
00000000000000000000000000000000 and
10000000000000000000000000000000, or in hexadecimal:
0x00000000 and 0x80000000