lundi 27 juillet 2020

Get random item based on multiple weights

I'm trying to work out how to choose an item at random, based on a couple of weights. Let me explain.

  • I have a person object which has an age group assigned, young, middle or old. This age group is a known variable.
  • I have 3 groups, each with their own chance of being selected, but also weighted towards an age group.

For example:

  • Group 1 has a 50% chance of being chosen, but more if they are young.
  • Group 2 has a 30% chance of being chosen by any age group.
  • Group 3 has a 20% chance of being chosen, but more if they are middle aged.

I'm not looking for a code hand out, but more theory to push me towards the correct answer. I know how to pick a group based on it's percentage alone, but I'm not quite sure how to weight it based on age group..

Thanks in advance. :)




Aucun commentaire:

Enregistrer un commentaire