Schoonology / weighted

A dead-simple module for picking a random item with weights.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to select multiple items in one query to the list?

jmancherje opened this issue · comments

For example, I'd like to select 5 unique items from a weighted list. I can write some functionality to do this myself, but I'm curious if there's a feature to specify a number of items to select.

There's not anything already built, mostly because with a weighted set like this, typically you want multiple items from the set to respect the weighted distribution itself, including duplicates.

What is the use case for getting a set of unique items? It could be a really useful feature, but I'm having trouble thinking of a use case.

My situation is pretty specific. Essentially I have a list of items that is continuously growing, I am sending a weekly newsletter containing 5 or so of these items selected at random. I want to avoid duplicates within a short period of time so I'm adding a column to track the time since an item was last sent in an email and using the square of that time to assign a weight.

I wrote a wrapper function that makes multiple selections removing each choice from the original list and reassigning the weights dynamically for a certain number of selections given as an argument.

I looked at adding this to the API, and couldn't find anything that didn't make other calling conventions worse. I'm going to close this for now, though I'm open to PRs with concrete ideas for where to take this.

If it's any consolation, I added a section to the README (along with a complete overhaul to make it easier to consume) linking back to your algorithm as an example of how to handle this: https://github.com/Schoonology/weighted#selecting-multiple-items-simultaneously