在范围内生成随机双精度

编程入门 行业动态 更新时间:2024-10-08 06:27:27
本文介绍了在范围内生成随机双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个双打,如下所示

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();

更多推荐

在范围内生成随机双精度

本文发布于:2023-10-26 06:46:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   精度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!