Skip to main content
Inspiring
December 31, 2008
Answered

quiz questions

  • December 31, 2008
  • 1 reply
  • 680 views
I'm creating a quiz using AS2. I have a total of 8 questions. I want to ask a question at random, then ask another question at random, but not ask the question that's already been used. I figured I'd create a new true/false statement each time I ask the question, then on the future question I can use those statements to rule out already used questions. Thanks for any help. Here's what I have so far:
This topic has been closed for replies.
Correct answer Ned Murphy
You would probably find it easier to radomize an array and use the random order from the first to the last. That way there is no issue with repeating the same question.

var questionsOrdered = new Array(1,2,3,4,5,6,7,8);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a

;
a

= t;
}
return a;
}

var questionsRandomized = shuffle(questionsOrdered);

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
December 31, 2008
You would probably find it easier to radomize an array and use the random order from the first to the last. That way there is no issue with repeating the same question.

var questionsOrdered = new Array(1,2,3,4,5,6,7,8);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a

;
a

= t;
}
return a;
}

var questionsRandomized = shuffle(questionsOrdered);

j9lemmonAuthor
Inspiring
December 31, 2008
Thanks!
Ned Murphy
Legend
December 31, 2008
You're welcome.