I’m running the same code on two machines. One (windows 7 64) uses:
java version "1.7.0"
java<TM> SE Runtime Environment <build 1.7.0-b147>
Java HotSpot<TM> 64-Bit Server VM <build 21.0-b17, mixed code>
and the other (linux 64) uses:
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)
I’m getting different outputs. I think it’s the VM because I copied the .class files, ran those, and still got different outputs.
Can anyone tell what could cause this?
EDIT:
The code is at http://pastebin.com/5EmYFkYn
The output should vary in between runs, yet not as drastically as it is between those two machines.
I get ~1.78 with Java 6 update 31 and ~3.8 with Java 7 update 7 on the same Linux box.
However if I get the random seed with
new Random(1)or some other number I get the same result. e.g. 1 always produces ~ 0.79 for the third number.Looking at the code for how the random seed is created, the code is completely different and I suspect the nextDouble() isn’t as random as it should be i.e. your values should vary more and it should matter so much how the seed was set.
I get different results every time I run it on the same machine with the same version of Java. Most likely as there are random elements in the code.
Since it is different between runs on the same machine, I would expect them to be different on different machines, and different versions of Java as well.
I would still seriously consider getting a newer version of Java than Java 7 “update nothing” or a version of Java 6 which is four years old.