tcod_sys/libtcod/src/mersenne_c.c
static uint32_t mt_rand(uint32_t mt[624], int *cur_mt)
{
#define MT_HIGH_BIT 0x80000000UL
#define MT_LOW_BITS 0x7fffffffUL
    uint32_t y;

    if (*cur_mt == 624) {
    	/* our 624 sequence is finished. generate a new one */
        int i;

        for (i=0;i<623;i++) {
            y = ( mt[i] & MT_HIGH_BIT ) | ( mt[i+1] & MT_LOW_BITS );
            if ( y & 1 ) {
            	/* odd y */
	            mt[i] = mt[ (i + 397) % 624 ] ^ (y >> 1) ^ 2567483615UL;
			} else {
				/* even y */
	            mt[i] = mt[ (i + 397) % 624 ] ^ (y >> 1);
			}
        }
        y = ( mt[623] & MT_HIGH_BIT ) | ( mt[0] & MT_LOW_BITS );
        if ( y & 1 ) {
        	/* odd y */
	        mt[623] = mt[396] ^ (y >> 1) ^ 2567483615UL;
		} else {
	        mt[623] = mt[396] ^ (y >> 1);
		}

        *cur_mt = 0;
    }

    y = mt[(*cur_mt)++];
    y ^= (y >> 11);
    y ^= (y << 7) & 2636928640UL;
    y ^= (y << 15) & 4022730752UL;
    y ^= (y >> 18);
    return y;
}
/* get the next random value from the mersenne twister array */
get the next random value from the mersenne twister array
get the next random value from the mersenne twister array
static uint32_t mt_rand(uint32_t mt[624], int *cur_mt)
{
#define MT_HIGH_BIT 0x80000000UL
#define MT_LOW_BITS 0x7fffffffUL
    uint32_t y;
    if (*cur_mt == 624) {
        int i;
        for (i=0;i<623;i++) {
            y = ( mt[i] & MT_HIGH_BIT ) | ( mt[i+1] & MT_LOW_BITS );
            if ( y & 1 ) {
	            mt[i] = mt[ (i + 397) % 624 ] ^ (y >> 1) ^ 2567483615UL;
			} else {
	            mt[i] = mt[ (i + 397) % 624 ] ^ (y >> 1);
			}
        }
        y = ( mt[623] & MT_HIGH_BIT ) | ( mt[0] & MT_LOW_BITS );
        if ( y & 1 ) {
	        mt[623] = mt[396] ^ (y >> 1) ^ 2567483615UL;
		} else {
	        mt[623] = mt[396] ^ (y >> 1);
		}
        *cur_mt = 0;
    }
    y = mt[(*cur_mt)++];
    y ^= (y >> 11);
    y ^= (y << 7) & 2636928640UL;
    y ^= (y << 15) & 4022730752UL;
    y ^= (y >> 18);
    return y;
}
static uint32_t mt_rand ( uint32_t mt [ 624 ] , int * cur_mt ) { #define MT_HIGH_BIT  0x80000000UL
 #define MT_LOW_BITS  0x7fffffffUL
 uint32_t y ; if ( * cur_mt == 624 ) { int i ; for ( i = 0 ; i < 623 ; i ++ ) { y = ( mt [ i ] & MT_HIGH_BIT ) | ( mt [ i + 1 ] & MT_LOW_BITS ) ; if ( y & 1 ) { mt [ i ] = mt [ ( i + 397 ) % 624 ] ^ ( y >> 1 ) ^ 2567483615UL ; } else { mt [ i ] = mt [ ( i + 397 ) % 624 ] ^ ( y >> 1 ) ; } } y = ( mt [ 623 ] & MT_HIGH_BIT ) | ( mt [ 0 ] & MT_LOW_BITS ) ; if ( y & 1 ) { mt [ 623 ] = mt [ 396 ] ^ ( y >> 1 ) ^ 2567483615UL ; } else { mt [ 623 ] = mt [ 396 ] ^ ( y >> 1 ) ; } * cur_mt = 0 ; } y = mt [ ( * cur_mt ) ++ ] ; y ^= ( y >> 11 ) ; y ^= ( y << 7 ) & 2636928640UL ; y ^= ( y << 15 ) & 4022730752UL ; y ^= ( y >> 18 ) ; return y ; }
get the next random value from the mersenne twister array
get the next random value from the mersenne twister array
/* our 624 sequence is finished. generate a new one */ /* odd y */ /* even y */ /* odd y */