Created
October 7, 2022 19:58
-
-
Save DeplorableMountaineer/6a28fc47320057dbcfc89f695336e9ba to your computer and use it in GitHub Desktop.
Routine with bug for getting array element by probability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private DropConfig SelectRandomItem(int level){ | |
float totalChance = GetTotalChance(level); | |
float randomRoll = Random.Range(0, totalChance); | |
float chanceTotal = 0; | |
foreach(DropConfig drop in potentialDrops){ | |
chanceTotal += GetByLevel(drop.relativeChance, level); | |
if(chanceTotal > randomRoll) return drop; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment