获取随机值从SQLite表SQLite

2023-09-06 16:41:59 作者:小三控 い

我目前工作的一个Android应用程序,我想从看起来像这样一个数据库表中的随机值:

I am currently working on an Android app and I am trying to get a random value from a database table that looks like this:

| ID | Score|
| 1  | 20   |
| 2  | 5    |
| 5  | 5    |
| 6  | 5    |
| 14 | 15   |

(让我们假设这些是在表中的唯一值),

(lets assume these are the only values in the table)

我想从这个表有时间ID 1 40%,ID的时间2 10%的随机值,ID的时间为5 10%,依此类推......结果如果这甚至有可能,你会怎么做呢?

I would like to get a random value from this table that has ID 1 40% of the time, ID 2 10% of the time, ID 5 10% of the time and so on... If that is even possible, how would you go about it?

推荐答案

给定一个列表<整数GT; 添加()每首歌指数评分次, Col​​lections.shuffle() 列表,按顺序播放。为了获得更好的效果,跳过连续重复。更多这里。

Given a List<Integer>, add() each song index score times, Collections.shuffle() the list, and play in order. For better results, skip successive duplicates. More here.