title: Android How to get random sqlite data?
body: <p>This is my DateBaseHelper
           public Cursor getQuestionsFromQuizID(int quizID){</p>
  
  <pre><code>             Integer quiz = Integer.valueOf(quizID);
  
               return myDataBase.rawQuery("select * from Questions where quizID ="+quiz.toString(), null );
  
       }
  
       public Cursor getAnswersFromQuestionID(int questionID, int quizID){
  
               Integer question = Integer.valueOf(questionID);
               Integer quiz = Integer.valueOf(quizID);
  
               return myDataBase.rawQuery("select * from Answers where questionID = "+question.toString()+" and quizID = "+quiz.toString(), null );
       }
  
      public Boolean isAnswerCorrect(int answerID) {
  
              Integer answer = Integer.valueOf(answerID);
              int correctBit;
  
              Cursor cursor = myDataBase.rawQuery("select * from Answers where _id ="
                              + answer.toString(), null);
  
              cursor.moveToFirst();
              correctBit = cursor.getInt(3);
  
              if (correctBit == 1) {
                      return true;
              } else {
                      return false;
              }
  
      }
  
      public int getQuestionCountByQuizID(int quizID){
  
              Integer quiz = Integer.valueOf(quizID);
  
              Cursor cursor = myDataBase.rawQuery("select * from Questions where quizID ="+quiz.toString(), null);
  
              cursor.moveToFirst();
  
              return cursor.getCount();
  
      }
  </code></pre>
  
  <p>...And I have quiz activity with method</p>
  
  <p>private void getNextQuestion() {
                  String question;</p>
  
  <pre><code>            // set question count text at the top of screen using string
              // concatenation
              Integer currentCount = new Integer(curQuestion + 1);
              ((TextView) findViewById(R.id.questioncount)).setText("Question "
                              + currentCount.toString() + " of "
                              + totalQuestionCount.toString());
  
              // get quizID based on which button was pressed on PickQuizActivity
              int quizID = getIntent().getExtras().getInt("quizID");
  
              // use returned cursor to get question as string
              Cursor questionCursor = myDbHelper.getQuestionsFromQuizID(quizID);
  
              questionCursor.moveToPosition(curQuestion);
  
              // getString(3): gets the zero-indexed column 2 from current row cursor
              // is on
              question = questionCursor.getString(2);
  
              // update UI to show question pulled from database
              ((TextView) findViewById(R.id.question)).setText(question);
  
              Cursor answerCursor = myDbHelper.getAnswersFromQuestionID(
                              curQuestion + 1, quizID);
  
              // set each answer text, there will always be 4 answers
              // also collect questionID for isCorrect check when onClick is called
              answerCursor.moveToFirst();
              ((TextView) findViewById(R.id.answer1)).setText(answerCursor
                              .getString(4));
              answerID1 = answerCursor.getInt(0);
  
              answerCursor.moveToNext();
              ((TextView) findViewById(R.id.answer2)).setText(answerCursor
                              .getString(4));
              answerID2 = answerCursor.getInt(0);
  
              answerCursor.moveToNext();
              ((TextView) findViewById(R.id.answer3)).setText(answerCursor
                              .getString(4));
              answerID3 = answerCursor.getInt(0);
  
              answerCursor.moveToNext();
              ((TextView) findViewById(R.id.answer4)).setText(answerCursor
                              .getString(4));
              answerID4 = answerCursor.getInt(0);
  
              // increment question counter, will be used to retrieve next question
              curQuestion++;
  
              // set flag for last question reached
              if (questionCursor.isLast()) {
                      lastQuestionReached = true;
              }
      }
  </code></pre>
  
  <p>So... When I wont to show random question, I edit sql, just add SORT BY RANDOM() LIMIT 10
  and my questions get mix up with answers...</p>
  
  <p>Can anybody know solution how to get random question without repeat?
  And how to aviod mixing data from question and answers?</p>