java – 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)”

嗯,什么?

nextFloat方法没有争议.调用它,然后将返回的值缩放到所需的范围内.

float minX = 50.0f;
float maxX = 100.0f;

Random rand = new Random();

float finalX = rand.nextFloat() * (maxX - minX) + minX;
http://stackoverflow.com/questions/6078157/random-nextfloat-is-not-applicable-for-floats

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:java – Random.nextFloat不适用于浮点数?