Lets just put it at its simplest, a table with two fields: ‘item_id’ & ‘times_seen’.
| item_id | times_seen |
----------+-------------
| 1001 | 48 |
| 1002 | 25 |
| 1003 | 1 |
| 1004 | 12 |
| 1005 | 96 |
| 1006 | 35 |
I’m trying to find a way to randomly select a row, but give preference to items that haven’t been selected much before.
(obviously, a second query would be sent to increment the ‘times-seen’ field after it has been selected)
Although my current “project” is a php/mysql one, I’d like language agnostic solutions if possible. I’d much rather have a math based solution that could be adapted elsewhere. I’m not opposed to a php solution though. I’d just like to be able to understand how the code works rather than just copy and paste it.
How about a SQL solution:
How much you multiply random with (Its a value between 0 and 1) depends on how much randomness you want..
Edit: http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand