vendredi 7 juillet 2023

Getting random items up to a certain price

I have a map of 73 items, each item has a price and I need to make a random list of 6 items, the sum of items must not be greater than N. I don't know what algorithm to use to implement this.

Can you tell me what algorithm can be done for this?

P.S. I'm want to write this functionality in Typescript

I can only think of an idiotic way, to randomize items until there is a list with the right sum or cheaper.




Aucun commentaire:

Enregistrer un commentaire