# Random numbers

**URL:** <https://forum.kirupa.com/t/random-numbers/26121>\
**Category:** Uncategorized\
**Created:** [July 19, 2003, 8:44pm UTC](https://forum.kirupa.com/t/random-numbers/26121 "2003-07-19T20:44:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilypdavis](https://avatars.discourse-cdn.com/v4/letter/e/8491ac/32.png) [@emilypdavis](https://forum.kirupa.com/u/emilypdavis)\
**Post date:** [July 19, 2003, 8:44pm UTC](https://forum.kirupa.com/t/random-numbers/26121/1 "2003-07-19T20:44:15Z")

</div>

this seems simple, but i am having a hard time doing this. For a class in school i am making a game similar to supermarket sweep. Incase you haven’t seen the show: in order to gain time for shopping you must answer 10 trivia questions at the beginning, but… I DONT WANT ALL OF THE QUESTIONS THE SAME!

\*i would like 20 questions to choose from  
\*i only want 10 questions to show up  
\*each question different (_no repeats_)  
\*after the 10th i would like to go on with the rest of the game

~~:love: i would love anyone even w/sugguestions! and hey… thanks for reading this! SORRY SO LONG :love: emily

---

<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:** [July 19, 2003, 10:30pm UTC](https://forum.kirupa.com/t/random-numbers/26121/2 "2003-07-19T22:30:02Z")

</div>

put your questions in an array, pic a random question, and remove that question.

```auto

questions = ["q1","q2","q3","q4","q5","q6","q7","q8","q9","q10"];

numberOfQuestions = 10;
theQuestion = [];

// run the pick-a-Q 10 times, fastest way
while(--numberOfQuestions-(-1)){
//pick a q and remove it
theQuestion[numberOfQuestions] = question.splice(random(this.length));
}

```

Now You have an array with the 10 random questions, named theQuestion. If you want a question nr1, use theQuestion[0]. If you want a question nr2, use theQuestion[1]. If you want a question nr3, use theQuestion[2]. Etc.

---

<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:** [July 20, 2003, 2:41pm UTC](https://forum.kirupa.com/t/random-numbers/26121/3 "2003-07-20T14:41:12Z")

</div>

thanks i know that do while loops would solve the never ending cycle questions. i learned that in visual basic. and i also learned a little bit about arrays last school year. but i’m confused by them still!

well ok… i have 10 labelled frames. each with a question, an answer box, and a check answer button, and clues. i want to keep these 10 frames… but when they click on the check answer button, if correct… i want it to jump to a random labelled frame! (and it does that!) but everynow and then i will get one question more than once. and i can’t get out of my loop!! So what do i need to relabel? the frames? the textboxes? if you need me to… i can send u the file! lol then u can help me! 🙂

PS. you said “If you want a question nr1, use theQuestion[0]” what do you mean by that? i’m confused… if u would please explain slowly in babysteps!

---

<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:** [July 20, 2003, 3:13pm UTC](https://forum.kirupa.com/t/random-numbers/26121/4 "2003-07-20T15:13:41Z")

</div>

arrays begin with array[0]. The first value will be 0. What he means that is if you want question number 1 then use  
theQuestion[0]. Get it?):

---

<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:** [July 20, 2003, 9:40pm UTC](https://forum.kirupa.com/t/random-numbers/26121/5 "2003-07-20T21:40:44Z")

</div>

How arrays work:

Look at this example:

```auto
anArray = new Array();//make an array with the name 'anArray'
anArray[0] = "john"; //fill the first place with the string john
anArray[1] = 12; // fill the second place with the number 12

```

This means that counting with an array starts with a 0. If you want the first entry, use anArray[0].

A quicker way to writ an array is this:

```auto
anArray = ["john",12];

```

The trick here is to save all the keyframe numbers into an array and remove the number once the question has been showed. Now you pick a random entry from that array and because the question you were already at is no longer there, is will never pick that question.

```auto
question = ["label1","label2","label3"];//and so on. This only needs to happen once!!

//to show and remove a question:
frame = question[n = random(question.length)];
question.splice(n);
gotoAndStop(n);

```

---

<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:** [July 21, 2003, 10:33pm UTC](https://forum.kirupa.com/t/random-numbers/26121/6 "2003-07-21T22:33:00Z")

</div>

thanks and i’ll try it out and get back to you!  
emily :flower:

---

<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:** [July 22, 2003, 2:59pm UTC](https://forum.kirupa.com/t/random-numbers/26121/7 "2003-07-22T14:59:52Z")

</div>

on (release) {  
if (questionbox0 == “lechuga”) {  
question = [“question1”, “question2”, “question3”];  
// and so on. This only needs to happen once!!  
// to show and remove a question:  
frame = question[n=random(question.length)];  
question.splice(n);  
gotoAndStop (n);  
} else {  
questionbox0 = “try again”;  
}  
}  
\<hr\>

[COLOR=orangered]^ that is what i used on the button to check the answer to see if it’s correct! and for some reason when i click the button instead of going to the random labelled frame… it goes to the first frame and doesnt move at all. well it mite be easier to get help if you IM’d me or whatever! IM me on: [/COLOR] [COLOR=blue]emilypdavis[/COLOR] [COLOR=orangered]THANKS bunches for trying to explain it to the DuMb BlOnDe![/COLOR]

---

<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:** [July 23, 2003, 12:45am UTC](https://forum.kirupa.com/t/random-numbers/26121/8 "2003-07-23T00:45:14Z")

</div>

Whoops. That should’ve been:

question.splice(n);  
gotoAndStop (frame);

My bad.

---

<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 8, 2003, 2:59pm UTC](https://forum.kirupa.com/t/random-numbers/26121/9 "2003-08-08T14:59:52Z")

</div>

ok the random frame thing works and all. but how would i also have the frames stop after 10? a do while loop? but how what is the code??

:love: LUV EMILY :love":
