I want to randomly select a single item out of three lists, where each list represents a different probability of selection.
I have three lists (can be also 3 arrays): high, mid, and low "priority".
I want to choose one item from those three lists by priority chance
E.g. From High 70% chance from mid 20% and from low rest 10%
However, some of the list could be empty (not all of them)
At least there is one item inside one of the lists
I'm looking for algorithm (any language, but prefer C# Java Python) that does it
I tried the following code (Python) but it doesn't do the job due the empty condition sometimes no item is selected even there is one.
x = random.randint(1,100)
if x < 71 and highChance != []:
return random.choice(highChance)
elif x >=71 and x < 91 and midChance != []:
return random.choice(midChance)
elif lowChance != []:
return random.choice(lowChance)