Skip to content

Instantly share code, notes, and snippets.

@DeplorableMountaineer
Created October 7, 2022 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeplorableMountaineer/6a28fc47320057dbcfc89f695336e9ba to your computer and use it in GitHub Desktop.
Save DeplorableMountaineer/6a28fc47320057dbcfc89f695336e9ba to your computer and use it in GitHub Desktop.
Routine with bug for getting array element by probability
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