vendredi 3 juillet 2015

Random row selection with different probabilities

I'm searching for a way to get from a table with 400-500 rows 1 random row but not with all the same probability.

For example: My table looks like:

Object - Rank

  • Object_A Top
  • Object_B Low
  • Object_C Normal

I got 3 possible ranks for an object and I would like that an object with the rank "Top" got three times more chance to get taken. It should be like there are 3 rows with Object_A in the table. Same for Normal but only two times the chance.

For now I got this code...

$result = mysqli_query($link, "SELECT * FROM objects ORDER BY RAND() LIMIT 1");




Aucun commentaire:

Enregistrer un commentaire