本文介绍了在范围内生成随机双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个双打,如下所示
I have two doubles like the following
double min = 100; double max = 101;并且使用随机生成器,我需要在min和max范围之间创建一个double值。
and with a random generator, I need to create a double value between the range of min and max.
Random r = new Random(); r.nextDouble();但这里没有任何内容可以指定范围。
but there is nothing here where we can specify the range.
推荐答案生成 rangeMin 和 rangeMax :
Random r = new Random(); double randomValue = rangeMin + (rangeMax - rangeMin) * r.nextDouble();更多推荐
在范围内生成随机双精度
发布评论