gpt4 book ai didi

java - 无法随机生成两个数字之间的数字

转载 作者:行者123 更新时间:2023-12-02 06:00:20 26 4
gpt4 key购买 nike

使用此代码我一直在尝试获取它们之间的号码
我使用的是 double ,因此我可以使用负数

double minX = plugin.getConfig().getDouble("location.min.x");
double maxX = plugin.getConfig().getDouble("location.max.x");
double randomX = random.nextDouble(maxX-minX) + minX;

但是我得到了

The method nextDouble() in the type Random is not applicable for the arguments (double)

但是如果我将它们设置为整数,它就可以正常工作。

最佳答案

  • nextDouble(),...统一返回下一个伪随机数从此随机数中分配介于 0.0 和 1.0 之间的 double 值生成器的序列。

所以将其更改为:

double randomX = random.nextDouble()*(maxX - minX) + minX;

关于java - 无法随机生成两个数字之间的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22725191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com