我对编程很陌生,为了生活,我无法解决为什么我收到错误:" next(int)在java中保护了访问权限。 util.Random"
这里是错误发生在......的代码
/**
* Generates Random Width Multiplier
*/
public static double randomRMultiplier() {
Random randM = new Random();
double randomMultiplier;
//Calculates a random value between 12 and 20
//(Divided by 10 to make a multiplier)
do {
switch(difficultyMark) {
case 1:
randomMultiplier = (randM.next((21-11) + 1) + 11); //Randoms between 11 and 21
break;
case 2:
randomMultiplier = (randM.nextInt((20-12) + 1) + 12); //Randoms between 12 and 20
break;
case 3:
randomMultiplier = (randM.nextInt((19-13) + 1) + 13); //Randoms between 12 and 20
break;
}
} while ( randomMultiplier > 14 & randomMultiplier < 18); //Excludes 15,16,17 as they are too similar to golden values(16-->1.6)
randomMultiplier = randomMultiplier / 10; //Divide by ten to make decimal multiplies
return randomMultiplier;
}
答案 0 :(得分:6)
我认为你并不打算直接使用它。
它实际上是一个&#34;实用程序&#34;所有其他 next*
调用使用的函数,以及如果使用更合适的类将Random
子类化,例如某些内容可以覆盖的函数不是线性同余的。
根据您的代码,我建议您不小心使用next
打算使用nextInt
。