I have a two long lists. Example:
good = ["Good thing1", "Good thing2", "Good thing3", "Good thing4", "Good thing5", ...]
bad = ["Bad thing1", "Bad thing2", "Bad thing3", "Bad thing4", "Bad thing5", ...]
The number of players can change:
players = 5
Each player has a 43% chance that a good thing will happen (or a 57% chance that a bad thing will happen). No two players can have the same good or bad outcome.
I tried to do a weighted outcome like this:
weighted_outcome = good * 43 + bad *57
random.sample(weighted_outcome, 5) # Where 5 is the number of players
but I get duplicates. If I do this as a set, then the weighted outcome becomes unweighted, as in this example:
weighted_outcome = good * 43 + bad *57
random.sample(list(set(weighted_outcome)), 5) # Where 5 is the number of players
Am I correct in assuming that the only way to make this weighted is to create a new unique weighted list? like in this example where I have a 70% good outcome and a 30% bad outcome:
weighted_result = []
weighted_result.append(random.sample(set(good), 7)
weighted_result.append(random.sample(set(bad), 3)
print(weighted_result)
I feel like this is still wrong, because at 70% there should still be a chance that every player had something good happen and a low chance that every player had something bad happen.
Aucun commentaire:
Enregistrer un commentaire