jeudi 22 février 2018

Find a random user according to a distribution based on the number of users' "likes"

I'm trying to find the most efficient approach to randomly pick a user from my users table.

It would be very easy if the expected distribution would be uniform : same probability for every user.

But in my case, I want this probability to be based on the number of 'likes' received by the user : the more 'likes' the user got, the most probable is to pick this user. I know that GameKit provides a class GKGaussianDistribution to generate random numbers following a Gaussian Distribution, but I don't think this fulfill my needs.

Another approach would be to fill an array with a unique Id for every "likes" from every users, and to pick one of them with arc4random_uniform(), and then look-up to its owner user, but I'm not sure that it is the most efficient way to proceed.

I guess this is a common problem that many of us had to resolve once in a life ?




Aucun commentaire:

Enregistrer un commentaire