为什么它说 next(int) 在 java.util.Random 中具有受保护的访问权限?
Why does it say next(int) has protected access in java.util.Random?
我是编程新手,我终生无法弄清楚为什么会收到错误消息:"next(int) has protected access in 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;
}
我不认为你打算直接使用它。
它实际上是一个被所有 other next*
调用使用的 "utility" 函数,如果你 subclass Random
与更合适的 class,例如不是线性同余的东西。
根据您的代码,我建议您不小心在您打算使用 nextInt
的地方使用了 next
。
我是编程新手,我终生无法弄清楚为什么会收到错误消息:"next(int) has protected access in 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;
}
我不认为你打算直接使用它。
它实际上是一个被所有 other next*
调用使用的 "utility" 函数,如果你 subclass Random
与更合适的 class,例如不是线性同余的东西。
根据您的代码,我建议您不小心在您打算使用 nextInt
的地方使用了 next
。