app behaves differently on iPad and on simulator

Hi

I’m building an app that simulates flashcards for studying for an exam. The program randomizes the order of the cards each time the program runs so they should show in a different sequence each time.

Lately the program has been running normally in the Corona simulator, but the app in the iPad shows the questions in the exact same order each time I close and re-open it. 

Even after I delete the app off the iPad and put a brand new build on it … it still displays the questions in the same order as before, so it seems to be ‘remembering’ something it’s should have forgotten.

cheers,

david

Can you post your randomizing code?

this function creates an array from 1 to however many cards I have:

createRandomArray = function() 

arrayToRandomizeQuestions = {}     – new array which will start with as many elements as there are questions. The array elements

                        – will hold integers e.g. array[1] = 1, array[2] = 2, etc.

    for rq=1, #questions do

      arrayToRandomizeQuestions[rq] = rq

      end

end

This function randomly chooses a number from the array and then removes that number from the array

getRandomIndexForQuestions = function ()

           

    randomNumber = math.random(1,#questions - questionsAnswered)    – random number chosen from 1 to the length of the questions array minus the number of questions answered.

    questionsIndex = table.remove(arrayToRandomizeQuestions, randomNumber)

     

end 

The iPad seems to have stored the whole array somewhere and is preserving it between launchings of the app

Hi @d2gp,

You might want to try “seeding” the random number function using this:

[lua]

math.randomseed( os.time() ) 

[/lua]

http://docs.coronalabs.com/api/library/math/randomseed.html

Brent

Yeah, that fixed it, thanks!!

Can you post your randomizing code?

this function creates an array from 1 to however many cards I have:

createRandomArray = function() 

arrayToRandomizeQuestions = {}     – new array which will start with as many elements as there are questions. The array elements

                        – will hold integers e.g. array[1] = 1, array[2] = 2, etc.

    for rq=1, #questions do

      arrayToRandomizeQuestions[rq] = rq

      end

end

This function randomly chooses a number from the array and then removes that number from the array

getRandomIndexForQuestions = function ()

           

    randomNumber = math.random(1,#questions - questionsAnswered)    – random number chosen from 1 to the length of the questions array minus the number of questions answered.

    questionsIndex = table.remove(arrayToRandomizeQuestions, randomNumber)

     

end 

The iPad seems to have stored the whole array somewhere and is preserving it between launchings of the app

Hi @d2gp,

You might want to try “seeding” the random number function using this:

[lua]

math.randomseed( os.time() ) 

[/lua]

http://docs.coronalabs.com/api/library/math/randomseed.html

Brent

Yeah, that fixed it, thanks!!