|
|
|
|
|
by Yrlec
5211 days ago
|
|
While not exactly a bug, but if you run this code in Java: for(int i = 0; i< 100; i++){
Random random = new Random(i);
System.out.println(random.nextDouble());
}
It prints the following sequence (at least on JDK 7 and Win 7): 0.730967787376657
0.7308781907032909
0.7311469360199058
0.731057369148862
0.7306094602878371
0.730519863614471
0.7307886238322471
0.7306990420600421
0.7302511331990172
0.7301615514268123
I know that you're not supposed to recreate the Random-instance like that but it's still a bit odd that the initial values in each sequence are so similar to each other. |
|
Your seed value from 0-100 is only varies in the last 6 bits out of 64 bits. Which I assume probably caused this whatever psuedo-random function Java is using to generate very similar value for seeds with that low level of entropy. You can look up the formula in Java SDK and do the math.
There's no need to pass in seed value to Random constructor unless you really want to reproduce the same random sequence.