infernalstudios / Mining-Master

Apache License 2.0
0 stars 4 forks source link

[EXTREMELY MINOR] MalachiteMeteoriteFeature doesn't use chanceToGenerate correctly. #4

Closed SwanX1 closed 2 years ago

SwanX1 commented 2 years ago

MalachiteMeteoriteFeature doesn't use config.chanceToGenerate correctly. It's currently checking for rand.nextInt(100) < config.chanceToGenerate It will work when chance is 100 and above, however will fail to compute the chance correctly otherwise. You see, Random.nextInt(bound) gets a random integer from 0 (inclusive) to the specified bound (exclusive). When you're generating an integer you can get the numbers 0 through 99. The chance range (specified 0 - 100) doesn't fit this. If you use 100, of course, the random integer will always be smaller than the range, so it will always generate. If you set the chance to 99, you will have a 98 in 99 chance of generating the island, not 99 in 100. When you set the chance to 0, you still have a 1 in 99 chance of generating the island. The revised version of the given check should be or rand.nextInt(100) + 1 <= config.chanceToGenerate. This issue would only be prevalent if a user-modifiable config is added.

Dariensg commented 2 years ago

This is incorrect. The statement you've given is functionally identical to the existing one. If you give the chance of 99, all values 0-98 will cause the meteorite to generate, but a 99 will not. This is in fact, a 99 in 100 chance of generation, just as the chance value indicates.

SwanX1 commented 2 years ago

my bad g