jeudi 9 mai 2019

In Ruby, how can one make a weighted random selection by least weight?

If I have the array :

ar = [1,3,5,3,6,1,4,6,7,6,6,6,6,6]

I could reduce this to the amount of occurrences :

counts = {1=>2, 3=>2, 5=>1, 6=>7, 4=>1, 7=>1}

Now I would like to choose at random with the least used number in ar being more weighted

I understand how I could easily make a weighted random choice based on most commonly used number, but not its inverse.




Aucun commentaire:

Enregistrer un commentaire