lundi 23 octobre 2017

Getting random key from Map based on the probabilities of the value

I have a map of size 10000. The values(float) are the probabilities of that key(string), non-negative entries that add up to one.

E.g. Key(Value): A(0.5);B(0.3);C(0.2)

How would you get a random key based on the probability "vector" (I know I do not have a vector) e.g. {0.5,0.3,0.2}?

I can use C++11.

Thank you.

Aucun commentaire:

Enregistrer un commentaire