Random Questions

I have made a quiz which has 20 questions. 15 questions are asked at random. However, being at random some questions are repeated. How do I shuffle questions rather than use random? Any help appreciated


quest1 = "Your Question"
quest2 = "Your Question"
quest3 = "Your Question"
//and so on (copy and paste)
 
rand = Math.round(Math.random()*19+1)
//rand = a random number between 1 and 20
//http://www.kirupa.com/developer/actionscript/tricks/random.htm
dynamicText = quest+rand 
//I'm sure there are many other methods
//but this is at the top of my head

I think that works…But i’m not sure how to do this though:
When a question has been displayed (eg: quest15) how to not display it again

Maybe someone can help me there…:stuck_out_tongue:

Does this help?


questions = ["q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10",
	    "q11", "q12", "q13", "q14", "q15", "q16", "q17", "q18", "q19",
	    "q20", "q21", "q22", "q23", "q24", "q25"];

holdNumber = 10; // How many questions to hold back. 

while(questions.length>holdNumber){
	rNum = Math.floor(Math.random()*(questions.length));
	trace(questions[rNum]);
	questions.splice(rNum,1);
}

You’ll probably have to change it to fit your needs, but I think the logic is covered here.

Actually scratch that, this one is easier to use (no stupid “hold number”)


questions = ["q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10",
	    "q11", "q12", "q13", "q14", "q15", "q16", "q17", "q18", "q19", "q20"];

askNumber = 15; // how many questions to ask from the array.

for(i = 0; i < askNumber; i++){
	rNum = Math.floor(Math.random()*(questions.length));
	trace(questions[rNum]);
	questions.splice(rNum,1);
}

Thanks for the help - I’ll give it a go