/* *
 * Title:
 * Description:
 * Copyright:
 * Notice:
 * @Version
 */


package umontreal.iro.lecuyer.rng;

import umontreal.iro.lecuyer.util.PrintfFormat;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.io.Serializable;

/**
 * Implements the {@link RandomStream} interface via inheritance from
 * {@link RandomStreamBase}. The backbone generator is the MT19937
 * Mersenne Twister, proposed by Matsumoto and Nishimura, which has a state size of 19937 bits and a period length of
 * approximatively  219937.
 * Each instance uses another {@link CloneableRandomStream} to fill its initial state.
 * With this design, the initial states of successive streams are not
 * spaced by an equal number of steps, and there is no guarantee that
 * different streams do not overlap, but damaging overlap is unlikely
 * because of the huge size of the state space.
 * The seed of the RNG, and the state of a stream at any given
 * step, is a 624-dimensional vector of 32-bit integers.
 * The output of nextValue has 32 bits of precision.
 * 
 */
public class MT19937 extends RandomStreamBase  {

   private static final long serialVersionUID = 70510L;
   //La date de modification a l'envers, lire 10/05/2007

   private static final double NORM = 1.0 / 0x100000001L;   // 1/(2^32 + 1)

   private static final int N = 624;
   private static final int M = 397;
   private static final int[] MULT_MATRIX_A = {0x0, 0x9908B0DF};
   private static final int UPPER_MASK = 0x80000000;
   private static final int LOWER_MASK = 0x7FFFFFFF;

   private int[] state;
   private int state_i;

   private CloneableRandomStream seedRng;

   private void fillSeed() {
      state_i = N;

      for(int i = 0; i < N; i++)
         state[i] = (int)((long)(seedRng.nextDouble() * 0x100000000L));
   }
 

   /**
    * Constructs a new stream, using rng to fill its initial state.
    * 
    * @param rng used to build the seed
    * 
    * 
    */
   public MT19937 (CloneableRandomStream rng)  {
      seedRng = rng;
      name = null;

      state = new int[N];

      //note : on pourrait directement appeler fillSeed, sauf qu'il y aurait
      //       des incoherences si le rng a deja ete appele
      resetStartStream();
   } 


   /**
    * Constructs a new stream with the identifier name
    *   (used in the toString method).
    * 
    * @param rng used to build the seed
    * 
    *   @param name name of the stream
    * 
    */
   public MT19937 (CloneableRandomStream rng, String name)  {
      this(rng);
      this.name = name;
   } 

   /**
    * Clones the current generator and return its copy.
    *  
    *  @return A deep copy of the current generator
    * 
    */
   public MT19937 clone()  {
      MT19937 retour = null;
      retour = (MT19937)super.clone();
      retour.state = new int[N];
      for (int i = 0; i
                    



        
      

Ads help maintain this website.