Select random item with weight

前端 未结 5 1770
执笔经年
执笔经年 2020-12-15 00:48

I have a list of approx. 10000 items. The current situation is that every item has an associated weight (priority or importance). Now the smallest weight is -100

5条回答
  •  忘掉有多难
    2020-12-15 00:53

    If you're storing your data in a database, you can use SQL:

    SELECT * FROM table ORDER BY weight*random() DESC LIMIT 1
    

提交回复
热议问题