public final synchronized void setSeed ( int [ ] buf ) { int length = buf . length ; if ( length == 0 ) throw new IllegalArgumentException ( "Seed buffer may not be empty" ) ; // ---- Begin Mersenne Twister Algorithm ---- int i = 1 , j = 0 , k = ( N > length ? N : length ) ; setSeed ( MAGIC_SEED ) ; for ( ; k > 0 ; k -- ) { mt [ i ] = ( mt [ i ] ^ ( ( mt [ i - 1 ] ^ ( mt [ i - 1 ] >>> 30 ) ) * MAGIC_FACTOR2 ) ) + buf [ j ] + j ; i ++ ; j ++ ; if ( i >= N ) { mt [ 0 ] = mt [ N - 1 ] ; i = 1 ; } if ( j >= length ) j = 0 ; } for ( k = N - 1 ; k > 0 ; k -- ) { mt [ i ] = ( mt [ i ] ^ ( ( mt [ i - 1 ] ^ ( mt [ i - 1 ] >>> 30 ) ) * MAGIC_FACTOR3 ) ) - i ; i ++ ; if ( i >= N ) { mt [ 0 ] = mt [ N - 1 ] ; i = 1 ; } } mt [ 0 ] = UPPER_MASK ; // MSB is 1; assuring non-zero initial array // ---- End Mersenne Twister Algorithm ---- }
This method resets the state of this instance using the integer array of seed data provided . This is the canonical way of resetting the pseudo random number sequence .