I’m trying to generate several random doublesbetween 0 and 1. This is the code I ran but the numbers coming back are very close together. I want numbers that are uniformally distributed over [0,1] or at least [0,1). I
public class MyClass
long seed = System.currentTimeMillis();
......
public double returnRandom() {
Random rand = new Random();
seed += 4; //update the seed
rand.setSeed(seed);
return rand.nextDouble();
}
(loop over array to populate) I end up with:
[0.10233441769044727]
[0.10484270731218648]
[0.1044843653222054]
[0.10412603823338551]
I would recommend that you not update the seed. You should also make Random a class instance and not instantiate one every time you call that method.