I have the following MatLab code:
randn('seed', 1);
rand('seed', 1);
A = 0.1*randn(5, 10)
And I am trying to write JAVA code that produces exactly the same result.
Here is my JAVA code:
import java.util.Random;
import java.lang.Math;
public class HelloWorld
{
static double[][] random_normal_matrix(Random r, int x, int y)
{
double tmp[][] = new double[x][y];
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
tmp[i][j] = 0.1*r.nextGaussian();
return tmp;
}
public static void main(String[] args)
{
Random r = new Random();
r.setSeed(1);
double tmp[][] = random_normal_matrix(r, 5, 10);
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 10; j++)
System.out.print(tmp[i][j]+" ");
System.out.println();
}
}
}
As you can see if you run the code, here https://octave-online.net/ and here https://www.compilejava.net/ the results are very different. The issue is not just some difference in precision.
Can someone please explain how I can get the same results?