本文介绍了Random.nextFloat不适用于浮点数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
float minX = 50.0f;
float maxX = 100.0f;
Random rand = new Random();
float finalX = rand.nextFloat(maxX - minX + 1.0f) + minX;
"Random类型的nextFloat()方法不适用于参数(float)"
"The method nextFloat() in the type Random is not applicable for the arguments (float)"
嗯,什么?
推荐答案
nextFloat
方法不带参数.调用它,然后在所需范围内缩放返回值.
The nextFloat
method doesn't take an argument. Call it, then scale the returned value over the range you want.
float minX = 50.0f;
float maxX = 100.0f;
Random rand = new Random();
float finalX = rand.nextFloat() * (maxX - minX) + minX;
这篇关于Random.nextFloat不适用于浮点数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!