jeudi 5 novembre 2015

How can I calculate the score of buyers and randomly select one using MySQL?

I have asked a similar question before, but the answers were not exact, due to my problem not being clear enough. I did accept the answer because it fit my question, but I'm still not sure of the next step, so here is me, trying again.

I am working on a lottery system, which is, I've heard, based on fitness proportionate selection. I am not good enough with algorithms to be certain though, so I am going to describe the selection criteria anyway.

I am selling two products. Buying product number 1 gives the buyer 10 tickets in the lottery, and buying product number 2 gives them 15 tickets. At the end, all tickets are put together into a metaphoric bucket, and a buyer is randomly drawn. Having more tickets does improve your chances, but doesn't guarantee being chosen.

In my programming language (PHP), I have an array that has the points for each product, like this:

[
    1 => 10,
    2 => 15
]

Now, taking into account that the product weights are not stored into the database, what is the query to select one (or more) random buyers, taking their fitness (i.e. the number of tickets they've earned) into account?

I'm not good with algorithms, so I'd also appreciate it if your answer would include information for an algorithms beginner.




Aucun commentaire:

Enregistrer un commentaire