Let's say I have a collection of objects. I have another collection of likes, each one by a specific user and toward a specific object. Thus, over time through user ratings, each object has a variable amount of likes (all greater than 0).
I want to choose an object from this collection. Objects with more likes should be chosen more frequently, but objects with lower likes should also be sometimes chosen to give them a chance.
The algorithm I have in mind now is to order the objects by likes, and generate a random number, and use the number to choose a random object within a range. Assuming I had a hundred objects, 50% of the time objects from 0-10 are chosen, 25% of the time 10-15, and 25% of the time 15-100.
The obvious problem with this algorithm is scalability. When theirs 1000000s of objects, returning an array of all of them takes time. Does anyone have a better solution? THe database is implemented in mongodb.