I'm trying to get random double numbers between 1.0 and 10.0 using the Random.nextDouble()
as such:
double number = 1.0 + (10.0-1.0) * Random.nextDouble();
Simulating this 10,000 times I find out that the probability of 1.0 and 10.0 is lower than the rest. The only way to get these number would require Random.nextDouble()
to be either 0.0 or 1.0. So essentially since Random.nextDouble()
gives a random number inbetween 0.0 and 1.0 it's less likely to actually result in 0.0 or 1.0.
Is there a way to mend this I wonder? Or should I try a completely different way as a whole?
EDIT:
So the problem lied indeed with rounding the numbers off to 1 decimal after generating a random double. A very crude solution I did now instead was generate a randomIntValue
between 0 and 91 and then initialise the double number = 1.0 + (randomIntValue * 0.1)
as such.
This is not the cleanest option i'd say.