Comparing Mersenne Twister in Java and Matlab

I am comparing mersenne twister in Java and matlab. I use the same seed in both. My problem is that when I print ten numbers from each number generator (Mersenne Twister, working in Java and Matlab respectively), the result does not seem to match. The output from the Matlab version is printed every second number from a program in Java.

Java fingerprints:

0.417, 0.997, 0.720, 0.932, 0.0001.

Matlab prints:

0.417, 0.720, 0.0001 ..

Can someone point me in the right direction to find out why this is happening?

Java:

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 < ant; i++){
            randt[i] = r.nextFloat()*1;
            System.out.println(randt[i]);    
        }
        System.out.println("------------twist");
    }
}

Matlab:

s = RandStream('twister','Seed',1)
RandStream.setGlobalStream(s);

r = 1 .* rand(1,10);

I use the standard implementation of Mersenne Twister in MatLab, the used Java version can be found here

+5
source share
1

Matlab rand() - 64- double. nextFloat(), 32- Java MersenneTwister. , Java - nextDouble , nextFloat, next(). nextFloat() nextDouble() Java TestRand, .

+2

All Articles