我正在努力计算用户获得物品的估计机会。他有 15 次尝试(可能会有所不同),有机会进入项目组,然后有机会获得确切项目。我可以看到两种方法,但没有一种是完美的。请看一下:
int userTries = 15;//Variable holding number of how many tries user has to get an item
double groupChance = 17;//Chance for user to get any item from the group
double itemChance = 80;//Chance for user to get specific item from the group
double simpleChance = groupChance * itemChance * userTries / 100.0;
int correctionTries = 10000;
int totalPassed = 0;
for (int i = 0;i < correctionTries;i++)
{
for (int x = 0;x < userTries;x++)
{
//Rnd.chance is checking if input chance was rolled, if chance is 17 then this method will return true in 17 tries out of 100
if (Rnd.chance(groupChance))
if (Rnd.chance(itemChance))
{
totalPassed++;
break;
}
}
}
double iterationChance = (double) totalPassed / (double) correctionTries * 100.0;
System.out.println("simple=" + simpleChance + " iteration=" + iterationChance);
当 groupChance 和 itemChance 较低(如 1 和 1)时,simpleChance 给出非常好的结果,但当机会较高时(如 17 和 80),它们与迭代结果相差很大。迭代解决方案的问题是,当我增加一个机会时,由于计算机会的运气不好,结果实际上会更低。我可以增加更正尝试来解决这个问题,但是再次计算相同的值时机会会有所不同,它也会对性能产生重大影响。
您是否知道有什么方法可以在低性能影响和良好估计的情况下计算再次计算后保持不变的机会?
MYYA
相关分类