remove_binomial
enchantment effect (used for Unbreaking) now uses a fast formula if the given value
and chance p
satisfy the following formula: value > 128 && value * p >= 9 && value * (1-p) >= 9
. The effect is expected to produce a newValue
where 0 <= newValue <= value
. That is, it cannot remove more than it asked, and it cannot add.
The fast formula, however, has a very small chance of violating this contract. Note how it is calculated:
double d = Math.floor(value * p);
double e = Math.sqrt(value * p * (1.0F - p));
return value - (int)Math.round(d + random.nextGaussian() * e);
Because a normal distribution can theoretically produce any number, it is possible that the value returned is negative, or above value
.
In my simulation, when value = 200, p = 0.950
, the chance of it returning negative value (adding durability) was 0.067%, and when value = 200, p = 0.0460
, the chance of it returning more than value (removing more durability) was 0.032%.
Comments 0
No comments.