获取随机值从SQLite表 [英] Getting random value from a SQLite table

查看:212
本文介绍了获取随机值从SQLite表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个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?

推荐答案

给定一个列表&LT;整数GT; 添加()每首歌指数评分次,<一个href=\"http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#shuffle%28java.util.List%29\"相对=nofollow> 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.

这篇关于获取随机值从SQLite表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆