I am making an Android app for automatic generation of question paper. In which I've made a database where I've stored questions but I'm facing problem in generating ramdon questions so that questions don't get repeated in the same question paper. Is there any specific function to generate random question from question set?
Asked
Active
Viewed 52 times
-4
-
For more details read information given below - what you mean. – Sree Jan 08 '18 at 04:34
-
I am making an Android app for automatic generation of question paper. In which I've made a database where I've stored questions but I'm facing problem in generating ramdon questions so that questions don't get repeated in the same question paper. Is there any specific function to generate random question from question set? – HRISHIKESH KEDAR Jan 08 '18 at 04:36
1 Answers
1
You can use Random keyword for order by and limit
the number of record you want.
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY RANDOM() LIMIT " + limit, null);
// use the cursor data
If you have data in List use below link https://stackoverflow.com/a/4229001/8603832

MJM
- 5,119
- 5
- 27
- 53
-
For a better performance see https://stackoverflow.com/questions/4114940/select-random-rows-in-sqlite – zhh Jan 08 '18 at 04:45
-