Hello Brothers. I am new and demanding inspiration from you. I am trying to make a quiz app in where the quiz “question Number” will appear randomly.It is okay if i select the question number change by 1. It is vising my all rows. But if I select the question number change by " integer 1 to 70(or any max)" It just showed 2 or 3 question successfully then showing null value ( and navigate the screen 1 as my program) .
My wish is the “question number” to be appeared randomly and will visit all the rows of my local DB.
Here is my block
That is an obvious issue. You change the question number by a random value between 1 to 70, so on average, it will increment it by 35. If you have 70 questions, and starting with #1, then on average the second one would be #36, and the 3rd one would be #71, and already out of range. And there is one chance out of 70 that the second question would be calculated to be #71 right away.
You need to either SET Question Number to the random integer, not to CHANGE it BY the random integer.
Or, if you increment it, you need to test if Question Number > 70 after incrementing it, and if the index is larger than the number of questions, you need subtract 70 from it, to keep the index in bound.
And for an optimal experience, you actually need a more sophisticated system, since there is a 1 chance out of 70 the second question would be the same as the first.
So, if you insist on changing the the Question Number by incrementing it, you need to pick a random number between 1 and 69, as picking 70 would bring you right back to the same one.
To solve your problem, you must create a temporary list of all items from which it will be deleted already randomly selected questions. Simply put, first select a random question out of 70, then of 69, then 68, etc.