vendredi 10 septembre 2021

Algorithm to determine random A from hashmap, the higher he value X of A is, the lower should be the chance of getting this A

this is my first post here - I will try my best.

So here is my algorithm I wan't to achieve explained in other words if you could not get it from the title: How could I get a random object (key in the hashmap) from a hashmap, but I have to consider the "weight" (I mean weight in terms of worth/price) (value to the key in the hashmap) of the object, the higher the weight, the lower the chance to get the object (key) randomly selected?

I sadly do not have any code to show you so far since I have not gotten up with an idea of the algorithm yet.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire