Android Question randon values in a fill list

Discussion in 'Android Questions' started by Edu Chamon, Aug 13, 2019.

  1. Edu Chamon

    Edu Chamon Member Licensed User

    Hi guys good morning (here in Brazil).
    Can you help me?
    I am asking some questions to help my daughter in school.
    use sqlite.
    rowid 1 question 1
    rowid 2 question 2
    rowid 3 question 3
    rowid 4 question 4
    if i read with order by desc i will have 4,3,2,1
    I throw these values in a list.
    I would like to have these same values in the list, but at random, would anyone have any ideas please?
    1st. time
    2nd instead 1,2,3,4
    and this interval increases as I ask more questions to avoid being monotone
    if I use rnd, sometimes it will not cover all values
  2. MarkusR

    MarkusR Well-Known Member Licensed User

    example , see also RndSeed
    Sub Process_Globals  
    Type MyData(no As Int,rowid As Int,text As String)

    Sub Test
    Dim l As List

    Dim q As MyData = 
        q.text = 

    Dim q As MyData = 
        q.text = 

    For Each q As MyData In l
    End Sub
    Edu Chamon likes this.
  3. Edu Chamon

    Edu Chamon Member Licensed User

    Wow, it was really cool, thank you very much
    MarkusR likes this.
  4. MarkusR

    MarkusR Well-Known Member Licensed User

    emexes likes this.
  5. emexes

    emexes Well-Known Member Licensed User

    Assuming that the number of questions is feasible to store in a list eg < 10000, then another approach is:
    Dim QuestionList As List

    QuestionList.AddAll( SQL_GET_ALL QuestionIds )

    Do While student still awake
        QuestionAt = 
    Rnd(0, QuestionList.Size)
        QuestionId = QuestionList.Get( QuestionAt )
        Question = SQL_GET( QuestionId )
        Ask Question

    If answer correct Then
            QuestionList.RemoveAt( QuestionAt )    
    'remove if correct, or leave in list if incorrect, to be asked again later
        End If
    which has the nice feature of re-asking questions until they are correctly answered... but not repeatedly over-and-over, just randomly in the future.
    Last edited: Aug 13, 2019
    Edu Chamon likes this.
  6. Edu Chamon

    Edu Chamon Member Licensed User

    Very cool, I learned a lot from your post, thank you very much.

    please, how could i return sql within the list?

    dim s as sql
    questionlist.addAll( rowid from questions order by random())
  7. Edu Chamon

    Edu Chamon Member Licensed User

    See how I'm doing. It will be something like this in the end

    Attached Files:

    • x.jpg
      File size:
      123.2 KB
    emexes likes this.
  8. MarkusR

    MarkusR Well-Known Member Licensed User

    the select statement is here in a string.
    example from link
    Dim Cursor As Cursor
    Cursor = SQL1.ExecQuery("SELECT col1, col2 FROM table1")
    For i = 0 To Cursor.RowCount - 1
    Cursor.Position = i
    you can work with the data in cursor direct or you can copy it into a struct/type and put this into a list.
    Edu Chamon and emexes like this.
  9. Edu Chamon

    Edu Chamon Member Licensed User

    Very cool, thank you very much.
    MarkusR likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice