# Random Questions

**URL:** <https://forum.kirupa.com/t/random-questions/60866>\
**Category:** random\
**Created:** [August 13, 2004, 9:05am UTC](https://forum.kirupa.com/t/random-questions/60866 "2004-08-13T09:05:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![john84](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@john84](https://forum.kirupa.com/u/john84)\
**Post date:** [August 13, 2004, 9:05am UTC](https://forum.kirupa.com/t/random-questions/60866/1 "2004-08-13T09:05:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 9:57am UTC](https://forum.kirupa.com/t/random-questions/60866/2 "2004-08-13T09:57:01Z")

</div>

```php

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…😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 10:06am UTC](https://forum.kirupa.com/t/random-questions/60866/3 "2004-08-13T10:06:04Z")

</div>

Does this help?

```auto

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 10:19am UTC](https://forum.kirupa.com/t/random-questions/60866/4 "2004-08-13T10:19:21Z")

</div>

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

```auto

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);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 12:47pm UTC](https://forum.kirupa.com/t/random-questions/60866/5 "2004-08-13T12:47:01Z")

</div>

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