5 Replies Latest reply on Jun 9, 2010 2:56 PM by kglad

    Random Quiz

    Feed_Me_Info_Plz Level 1

      I have completed a quiz based on multiple choice and it works perfectly. I wish to now add a feature to randomize the questions. I have 100 questions and dont want the same sequence when retrying the quiz. Can any one please assist with a code or a good tutorial to assist me.

       

      Thanks

        • 1. Re: Random Quiz
          kglad Adobe Community Professional & MVP

          add your questions to an array and pass that array to shuffleF().  it will then be randomized and you can iterate throught your shuffled array in sequence:

           

          yourArray = shuffleF(yourArray):

           

           

          //////// nothing below should be changed/////////////

          function shuffleF(a:Array):Array {
              n = a.length;
              while (n>1) {
                  k = Math.floor(Math.random()*n);
                  n--;
                  temp = a[n];
                  a[n] = a[k];
                  a[k] = temp;
              }
              return a;
          }

          1 person found this helpful
          • 2. Re: Random Quiz
            Feed_Me_Info_Plz Level 1

            not sure about the array, i have the question on frame 1 with the possible answers as buttons with a action goto Q2 then Q3

            etc. the correct answer button has a score++ added. All I want to do is instead of the goto action i want to have a action to randomize the questions between frame 1 and frame 100 until all questions have been asked and then goto label results.

             

            Would I be able to use the code supplied.

            • 3. Re: Random Quiz
              kglad Adobe Community Professional & MVP

              you'll need to change the code on each frame so instead of going to the next frame after each question/answer, you'll go to a frame listed in an array.  you can then randomize the frame numbers in that array.

              1 person found this helpful
              • 4. Re: Random Quiz
                Feed_Me_Info_Plz Level 1

                perfect so can I do this using your code.

                • 5. Re: Random Quiz
                  kglad Adobe Community Professional & MVP

                  yes, if you do as mentioned above.