Java Random.nextDouble() probability
<p>I'm trying to get random double numbers between 1.0 and 10.0 using the <code>Random.nextDouble()</code> as such:</p>

<pre><code>double number = 1.0 + (10.0-1.0) * Random.nextDouble();
</code></pre>

<p>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 <code>Random.nextDouble()</code> to be either 0.0 or 1.0. So essentially since <code>Random.nextDouble()</code> gives a random number inbetween 0.0 and 1.0 it's less likely to actually result in 0.0 or 1.0.</p>

<p>Is there a way to mend this I wonder? Or should I try a completely different way as a whole?</p>

<p>EDIT:</p>

<p>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 <code>randomIntValue</code> between 0 and 91 and then initialise the <code>double number = 1.0 + (randomIntValue * 0.1)</code> as such.</p>

<p>This is not the cleanest option i'd say.</p>