I'm trying to figure out the best way to code the random occurance of something based on percent without hard coding if-else for each percentage since it will be dynamic.
Ex:
Item 1 drops 20% of the time
Item 2 drops 60% of the time
Item 3 drops 20% of the time
I'm storing the itemID and percentage as HashMaps
// itemID, percentage
HashMap<Integer, Integer>
But is there a better way to store these pairs? I could create a new class with only 2 variables called Pair. Would a Pair class be more efficient than a HashMap for storing multiple itemID and percentage?
I somehow have to go through each item in the HashMap and get the percentages, then add all them up (20 + 60 + 20) to get 100.
I then have to do some random number generation to get a number then check which item will drop. To do this I may have to order check from lowest percentage to highest, but if 2 percentages are the same (20 + 20), then I'm not sure how to pick which one should be dropped.


