title: Comparing the Mersenne Twister in Java and matlab
body: <p>I'm comparing the mersenne twister in Java and matlab. I'm using the same seed in both.
  My problem is that when i print out ten numbers from each number generator (Mersenne Twister running in Java and Matlab respectively), the resulting output doesn't seem to match.
  The output data from the Matlab version prints out every second number from the program in Java.</p>
  
  <p>Java prints: </p>
  
  <blockquote>
    <p>0.417, 0.997, 0.720, 0.932, 0.0001..</p>
  </blockquote>
  
  <p>Matlab prints: </p>
  
  <blockquote>
    <p>0.417, 0.720, 0.0001..</p>
  </blockquote>
  
  <p>Can anyone point me in the right direction to figure out why this happens?</p>
  
  <p>Java:</p>
  
  <pre><code>public class TestRand {
      static MersenneTwister r = new MersenneTwister(1);
  
      public static void main(String[] args) {
  
          int ant = 10;
          float[] randt = new float[ant];
  
          for (int i = 0; i &lt; ant; i++){
              randt[i] = r.nextFloat()*1;
              System.out.println(randt[i]);    
          }
          System.out.println("------------twist");
      }
  }
  </code></pre>
  
  <p>Matlab:</p>
  
  <pre><code>s = RandStream('twister','Seed',1)
  RandStream.setGlobalStream(s);
  
  r = 1 .* rand(1,10);
  </code></pre>
  
  <p>I am using the standard implementation of the Mersenne Twister in MatLab, the Java-version I am using can be found <a href="http://www.cs.gmu.edu/~sean/research/mersenne/MersenneTwister.java" rel="nofollow">here</a></p>